.NET 5, Webassembly Project, Javascript Isolation, Exception: "Required property __jsObjectId not found"

Posted 3 years ago by Andreas
0

Hello Everyone,

I followed a simple example for JavaScript Isolation, I keep getting an error.

@inject IJSRuntime jsRuntime
    protected override async void OnInitialized()
    {
       var  module = await jsRuntime.InvokeAsync<JSObjectReference>("import", "./exampleJsInterop.js");
    }
export function showPrompt(message) {
    return prompt(message);
}

I already get the exception here so I do not even go further. Here is the Exception Details, I would greatly appreciate help, thanks, kind blessings, Andreas

Unhandled Exception:
System.Text.Json.JsonException: Invalid JSON
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.EndInvokeJS(JSRuntime jsRuntime, String arguments)
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.EndInvokeJS(String argsJson)
Uncaught Error: System.Text.Json.JsonException: Invalid JSON
Unhandled Exception:
Microsoft.JSInterop.JSException: An exception occurred executing JS interop: Required property __jsObjectId not found.. See InnerException for more details.
 ---> System.Text.Json.JsonException: Required property __jsObjectId not found.
   at Microsoft.JSInterop.Infrastructure.JSObjectReferenceJsonConverter`2[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[Microsoft.JSInterop.Implementation.JSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, IJSObjectReference& value)
   at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[Object](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadValueCore[Object](JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
   at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader)
   --- End of inner exception stack trace ---
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__15`1[[Microsoft.JSInterop.Implementation.JSObjectReference, Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at ReneeMcGuire.Client.Pages.Resources.OnInitialized() in D:\Development\Business\xxx\Web\xxx\Client\Pages\Resources.razor:line 244
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.ThreadPool.Callback()

 

 

  • 1

    The first thing that stands out is you're using OnInitialized() instead of OnInitializedAsync().

    Posted 3 years ago by selliott
  • 0

    Thx! tried with OnInitializedAsync as well yesterday or so and still the same :(. Cannot find anything on this error.

    Posted 3 years ago by Andreas
  • 1

    I looked into this and it looks like you should be able to use the original code and change JSObjectReference to IJSObjectReference. OnInitialized() was correct.

    The example you found was likely based on .Net 5.0 RC1, but a breaking change in .Net 5.0 RC2 changed this.

    Posted 3 years ago by selliott Edited 3 years ago
  • 0

    Great thank you so very much that was it :)!! Now it works!

        protected override async Task OnInitializedAsync()
        {
            var  module = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./exampleJsInterop.js");
            await module.InvokeVoidAsync("showPrompt", "This is a message");
        }
    Posted 3 years ago by Andreas
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 2
An error has occurred. This application may no longer respond until reloaded. Reload 🗙