question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor JS interop [Bug]

See original GitHub issue

Description

Calling JS from C# in MAUI-Blazor app not work.

Steps to Reproduce

  1. RCL with JS interop wrapped to C# class
  2. Call

Expected Behavior

Work same as with browser. With browser same RCL work.

Actual Behavior

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE: VS19.VS22
  • Platform Target Frameworks:
    • Android: emulator

"Object reference not set to an instance of an object."

   at Microsoft.AspNetCore.Components.WebView.Services.WebViewJSRuntime.BeginInvokeJS(Int64 taskId, String identifier, String argsJson, JSCallResultType resultType, Int64 targetInstanceId) in Microsoft.AspNetCore.Components.WebView.dll:token 0x6000113+0x0
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[IJSObjectReference](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args) in Microsoft.JSInterop.dll:token 0x600003a+0x10a
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.IJSObjectReference, Microsoft.JSInterop, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext() in Microsoft.JSInterop.dll:token 0x60000a8+0xf7
   at Obletsvet.Ui.Mobile.Components.SwipeMenu.InitAsync() in C:\Projects\Obletsvet\Obletsvet\src\Obletsvet.Ui.Mobile.Components\SwipeMenu.cs:line 35
   at Obletsvet.Ui.Mobile.Components.Shared.TopBar.OnAfterRenderAsync(Boolean firstRender) in C:\Projects\Obletsvet\Obletsvet\src\Obletsvet.Ui.Mobile.Components\Shared\TopBar.razor:line 97

Also notice #1245 and ipcSender looks like it is also not set in android

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MackinnonBuckcommented, Nov 17, 2022

If we enable scope validation, error like this will yield much more useful messages. Since we can’t reasonably change the IJSRuntime to be registered as a singleton service in MAUI Blazor, let’s use this issue to track enabling scope validation.

1reaction
Eiloncommented, Oct 14, 2021

I think that the JS interop type in your app needs to be registered as Scoped and not Singleton (just like in Blazor Server).

But we should try to make this have a better experience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blazor JS Interop is bugged in an hard to reproduce scenario.
On firefox, my odd setup (vite.js serving blazor and ts files), sometimes trigger an error. While I have not pinpointed the cause, it...
Read more >
asp.net core - JavaScript interop Error when calling ...
JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendererd. When prerendering is ...
Read more >
ASP.NET Core Blazor JavaScript interoperability (JS interop)
This article explains general concepts on how to interact with JavaScript in Blazor apps. A Blazor app can invoke JavaScript (JS) functions ...
Read more >
Error with JS interop in UI for Blazor
I am trying to integrate your blazor components in to my app. I am getting the following error: [2020-08-22T23:29:42.283Z] Error: Microsoft.
Read more >
JavaScript Interop Error in Blazor - JSException
Ran across this weird "Unexpected token '?'" error with JavaScript interop in Blazor. The solution was pretty simple, once I figured it out....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found