diff --git a/BlazorContextMenu/BlazorContextMenu.csproj b/BlazorContextMenu/BlazorContextMenu.csproj index 903c2dd..e6e8ac2 100644 --- a/BlazorContextMenu/BlazorContextMenu.csproj +++ b/BlazorContextMenu/BlazorContextMenu.csproj @@ -19,7 +19,7 @@ blazor blazor-component blazor-context-menu context-menu contextmenu menu blazor-menu blazorcontextmenu razor razor-components razorcomponents $(VersionSuffix) - 0.16.0 + 0.16.1 $(Version)-$(VersionSuffix) Blazor.ContextMenu diff --git a/BlazorContextMenu/Components/ContextMenuTrigger.cs b/BlazorContextMenu/Components/ContextMenuTrigger.cs index 844b18a..867a45e 100644 --- a/BlazorContextMenu/Components/ContextMenuTrigger.cs +++ b/BlazorContextMenu/Components/ContextMenuTrigger.cs @@ -89,11 +89,25 @@ protected override void OnInit() } } + #region Hack to fix https://github.com/aspnet/AspNetCore/issues/11159 + + public static object CreateDotNetObjectRefSyncObj = new object(); + + protected DotNetObjectRef CreateDotNetObjectRef(T value) where T : class + { + lock (CreateDotNetObjectRefSyncObj) + { + JSRuntime.SetCurrentJSRuntime(jsRuntime); + return DotNetObjectRef.Create(value); + } + } + #endregion + protected override async Task OnAfterRenderAsync() { if (!blazorContextMenuHandler.ReferencePassedToJs) { - await jsRuntime.InvokeAsync("blazorContextMenu.SetMenuHandlerReference", DotNetObjectRef.Create(blazorContextMenuHandler)); + await jsRuntime.InvokeAsync("blazorContextMenu.SetMenuHandlerReference", CreateDotNetObjectRef(blazorContextMenuHandler)); blazorContextMenuHandler.ReferencePassedToJs = true; } }