Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project created with net 8 template throws InvalidOperationException on first start #467

Closed
1 of 2 tasks
petergolde opened this issue Feb 24, 2024 · 5 comments · Fixed by #465
Closed
1 of 2 tasks

Comments

@petergolde
Copy link

Bug type

Other

Component name

No response

What happened?

I created a new MudBlazor application using the template:

dotnet new mudblazor --auth Individual --int Server --all-interactive -o MudBlazorTest

Then opened the application in Visual Studio 2022 Community and hit run.

--> Execution stops in RemoteJSRuntime.BeginInvokeJS with InvalidOperationException. See screenshot attached.
Screenshot MudBlazor

Expected behavior

No exception thrown.

Reproduction link

https://github.com/petergolde/MudBlazorBugReport

Reproduction steps

  1. Create new application from command line using template and command line shown above.
  2. Start Visual Studio 2022 Community 17.8
  3. Open project created by dotnet new
  4. Click "Run" button in toolbar.

Relevant log output

Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code
JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.

Version (bug)

6.16.0

Version (working)

No response

What browsers are you seeing the problem on?

Microsoft Edge

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ScarletKuro
Copy link
Member

ScarletKuro commented Feb 24, 2024

Hi.
Weird, but I cloned your project, started it and not errors, as well navigated all pages but still no errors.
Visual Studio Enterprise v17.8.3
Would be also nice if you could show "call stack".
In addition update the libraries just in case to the latest
libs
the -rc libraries have some bugs (#453 (comment))

@petergolde
Copy link
Author

It must have something to do with my Debug options. If I unchecked that "Break when this exception type is unhandled", then it continues and runs ok. After unchecking that, I can't get it to reproduce again.

Looking at the call stack, it seems like this is a sort-of expected exception to happen with JS interop during pre-rendering. It seems to me it would be better to somehow detect the pre-rendering and not do the JS interop at all, but I suppose its OK the way it is.

It is not clear to me why my Visual Studio thought the exception was unhandled. Strange.

I guess it is fine to close this, but it was a bad first impression for me with MudBlazor.

@ScarletKuro
Copy link
Member

I'm not sure if it comes from our code or not, but Microsoft doesn't have any public API to identify what rendering mode is used, nor there is API to understand if the JsRuntime is available. You can understand it in a razor component (after the OnAfterRenderAsync lifecycle, and in our code we call JS in component when its available), but not in a service if it's using JS. There are also JS errors when circuit breaks JSDisconnectedException, TaskCanceledException and all we can do is to suppress those errors.

@erbatista
Copy link

erbatista commented Mar 8, 2024

I had a similar error with WebAssembly interactivity setup, and it went away by explicitly defining the MudBlazor version, and also make sure you're targeting the latest version of the .Net Core. In short, my project file went from:

   <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.2.23480.2" />
   <PackageReference Include="MudBlazor" Version="6.*" />

to:

  <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
  <PackageReference Include="MudBlazor" Version="6.17.0" />

@jperson2000
Copy link
Contributor

Hi everyone, I am working on upgrading the templates for MudBlazor 7.0.0 in this PR: #465. I haven't seen this error but I will test this project type for you.

@ScarletKuro ScarletKuro transferred this issue from MudBlazor/MudBlazor Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants