@using Microsoft.AspNetCore.Blazor.Browser.Interop @using BasicTestApp.InteropTest @using Microsoft.AspNetCore.Blazor

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 JavaScriptException ExceptionFromSyncMethod { get; set; } public JavaScriptException SyncExceptionFromAsyncMethod { get; set; } public JavaScriptException AsyncExceptionFromAsyncMethod { get; set; } public bool DoneWithInterop { get; set; } public async Task InvokeInteropAsync() { Console.WriteLine("Starting interop invocations."); await RegisteredFunction.InvokeAsync("BasicTestApp.Interop.InvokeDotNetInteropMethodsAsync"); Console.WriteLine("Showing interop invocation results."); var collectResults = RegisteredFunction.Invoke>("BasicTestApp.Interop.CollectResults"); 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 = JsonUtil.Serialize(interopResult.Value); invocations[interopResult.Key] = interopResultValue; } try { RegisteredFunction.Invoke("BasicTestApp.Interop.FunctionThrows"); } catch (JavaScriptException e) { ExceptionFromSyncMethod = e; } try { await RegisteredFunction.InvokeAsync("BasicTestApp.Interop.AsyncFunctionThrowsSyncException"); } catch (JavaScriptException e) { SyncExceptionFromAsyncMethod = e; } try { await RegisteredFunction.InvokeAsync("BasicTestApp.Interop.AsyncFunctionThrowsAsyncException"); } catch (JavaScriptException e) { AsyncExceptionFromAsyncMethod = e; } Invocations = invocations; DoneWithInterop = true; } }