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

Using the suggested method for a WPF-Blazor hybrid app, an exception is thrown if any of the blazor pages is set to an interactive server render mode #33509

Closed
fltrierweiler opened this issue Sep 2, 2024 · 10 comments · Fixed by #33820

Comments

@fltrierweiler
Copy link

Description

Is there any way to solve this?

Basically, there are a few pages in my app that must use @rendermode @(new InteractiveServerRenderMode(prerender: false)). I need the interactivity to use FluentUI Dialog components.

The web version works fine, but if I try to launch the WPF app, it immediately runs into the following exception:

NotSupportedException: Cannot supply a component of type 'X' because the current platform does not support the render mode 'Microsoft.AspNetCore.Components.Web.InteractiveServerRenderMode'.

I've tried adding services.AddRazorComponents().AddInteractiveServerComponents(); to the Form constructor, but that gives me another exception:

InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager' to type 'Microsoft.AspNetCore.Components.WebView.Services.WebViewNavigationManager'.

So now I'm stuck and I can't find any documentation providing answers. Is there a way to solve this?

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/wpf?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/hybrid/tutorials/wpf.md

Document ID

94872f14-0dce-0cf3-0d25-88f23ca8d8ef

Article author

@guardrex

@guardrex
Copy link
Collaborator

guardrex commented Sep 2, 2024

Hello @fltrierweiler ... Stand-by for sec, while I get an update on the WPF (and WinForms for that matter) + BWA plan ...

@danroth27 @mkArtakMSFT ... IIRC from earlier discussion, including with @BethMassi, I thought we're not supporting WPF (per this tutorial's guidance) with BWA in the framework/docs. Is that correct?

If so, I'd like to add a remark at the tops of the WPF and WinForms tutorials and steer devs to the MAUI+BWA tutorial.

@fltrierweiler
Copy link
Author

Hey @guardrex, thank you for your reply! I managed to find a workaround for this issue, at least for my specific problem. Turns out that the FluentUI Dialog components don't really need interactivity to work when I'm using them in the WPF version of the app, so I changed the project to set the render mode only for the web version, and now everything is working fine. Can I close this issue?

@guardrex
Copy link
Collaborator

guardrex commented Sep 6, 2024

Thanks for letting us know, @fltrierweiler.

Let's leave this issue open for a bit. Beth is OOF at the moment. We probably need some kind of remark in WinForms and WPF coverage to steer devs to the MAUI article/sample if they want Blazor Web App features. This issue will close automatically later when the PR merges.

@BethMassi
Copy link
Contributor

@guardrex the same pattern that we describe in the .NET 8 version of the MAUI Blazor Hybrid + Web sample would apply here as well.

https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/maui-blazor-web-app?view=aspnetcore-8.0#per-pagecomponent-server-interactivity

You need to add the InteractiveRenderSettings class to the shared RCL and then call the ConfigureBlazorHybridRenderModes method from the startup on the hybrid app.

Also, it is likely we won't finish this work item dotnet/aspnetcore#51235 so the same pattern would apply in .NET 9.

Hope this helps!

@guardrex
Copy link
Collaborator

Is the plan to overhaul those two articles to demonstrate the same pattern or leave them as they are and tell devs in the articles to implement the pattern explained by the MAUI article if they wish to support a BWA with their WinForms or WPF app? ... or perhaps do nothing at this time?

@BethMassi
Copy link
Contributor

I think we can leave the Winforms/WPF content as is. We do need some updates to the .NET 9 MAUI version of this one though. We're not going to get the fix in for ignoring the rendering modes in Blazor hybrid apps so we need to add instructions on how to add the InteractiveRenderSettings class. It's pretty straightforward using the new maui-blazor-web template though. I wrote it up and provide a sample here: https://github.com/BethMassi/BlazorHybridWebDemo

@guardrex
Copy link
Collaborator

guardrex commented Oct 3, 2024

I'm confused. A (plain) MAUI Blazor app doesn't include a Blazor (web) app. It just sets up a root component in index.html for the Routes component.

<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />

For ...

add instructions on how to add the InteractiveRenderSettings class

Isn't that all covered by the work we did earlier in the new MAUI Blazor with BWA article? ....

https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/maui-blazor-web-app?view=aspnetcore-8.0

not going to get the fix in for ignoring the rendering modes

I thought that would just mean that we won't need to make any 9.0 updates to that article.

@BethMassi
Copy link
Contributor

Ah sorry, I thought this was a discussion about sharing RCL with Blazor hybrid which this class addresses. And yes, this is covered in that article in the per page/component https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/maui-blazor-web-app?view=aspnetcore-8.0#per-pagecomponent-server-interactivity We should make a note about this in the .NET 9 version as well.

@guardrex
Copy link
Collaborator

guardrex commented Oct 3, 2024

You're right ... I changed the subject a little in using this issue to discuss if a web app RCL version of the WPF and WinForms articles would be written up. I understand that the answer on that is 'no' for now.

I'm not sure what note you mean to add. A note about what? ... and where?

@BethMassi
Copy link
Contributor

BethMassi commented Oct 3, 2024

I think somewhere in this section? https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/maui-blazor-web-app?view=aspnetcore-9.0#use-blazor-render-modes we should make a note about needing this class if you do want to support per page / component rendering modes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants