@using Microsoft.JSInterop @using BasicTestApp.InteropTest

Invocations

@foreach (var invocation in Invocations) {

@invocation.Key

@invocation.Value

}

Return values and exceptions thrown from .NET

@foreach (var returnValue in ReturnValues) {

@returnValue.Key

@returnValue.Value

}

Exceptions thrown from JavaScript

@nameof(ExceptionFromSyncMethod)

@ExceptionFromSyncMethod?.Message

@nameof(SyncExceptionFromAsyncMethod)

@SyncExceptionFromAsyncMethod?.Message

@nameof(AsyncExceptionFromAsyncMethod)

@AsyncExceptionFromAsyncMethod?.Message

@if (DoneWithInterop) {

Done with interop.

} @functions { public IDictionary ReturnValues { get; set; } = new Dictionary(); public IDictionary Invocations { get; set; } = new Dictionary(); public JSException ExceptionFromSyncMethod { get; set; } public JSException SyncExceptionFromAsyncMethod { get; set; } public JSException AsyncExceptionFromAsyncMethod { get; set; } public bool DoneWithInterop { get; set; } public async Task InvokeInteropAsync() { var inProcRuntime = ((IJSInProcessRuntime)JSRuntime.Current); Console.WriteLine("Starting interop invocations."); await JSRuntime.Current.InvokeAsync("jsInteropTests.invokeDotNetInteropMethodsAsync"); Console.WriteLine("Showing interop invocation results."); var collectResults = inProcRuntime.Invoke>("jsInteropTests.collectInteropResults"); ReturnValues = collectResults.ToDictionary(kvp => kvp.Key,kvp => System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(kvp.Value))); var invocations = new Dictionary(); foreach (var interopResult in JavaScriptInterop.Invocations) { var interopResultValue = Json.Serialize(interopResult.Value); invocations[interopResult.Key] = interopResultValue; } try { inProcRuntime.Invoke("jsInteropTests.functionThrowsException"); } catch (JSException e) { ExceptionFromSyncMethod = e; } try { await JSRuntime.Current.InvokeAsync("jsInteropTests.asyncFunctionThrowsSyncException"); } catch (JSException e) { SyncExceptionFromAsyncMethod = e; } try { await JSRuntime.Current.InvokeAsync("jsInteropTests.asyncFunctionThrowsAsyncException"); } catch (JSException e) { AsyncExceptionFromAsyncMethod = e; } Invocations = invocations; DoneWithInterop = true; } }