dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.01k forks source link

InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.WebView.Services.WebViewNavigationManager' to type 'Microsoft.AspNetCore.Components.Routing.IHostEnvironmentNavigationManager'. #47613

Closed mediabuff closed 1 year ago

mediabuff commented 1 year ago

Is there an existing issue for this?

Describe the bug

Hi, I am trying to host Razor views (*.cshtml) in an hybrid wpf app (BlazorWebView). Got everyting working with memory based OWIN loopback. But ran into this cast when Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer tries to render it.

It appears webview NavigationManager does not implement IHostEnvironmentNavigationManager, which the MVC stack expects.

Should'nt webview NavigationManager be implemented similiar to

https://github.com/dotnet/aspnetcore/blob/main/src/Components/Server/src/Circuits/RemoteNavigationManager.cs

Expected Behavior

Implement IHostEnvironmentNavigationManager on Webview NavigationManager.

Steps To Reproduce

Start with Wpf Hybrid app and add MVC stack with owin middleware.

Exceptions (if any)

InvalidCastException

.NET Version

.Net 7

Anything else?

No response

javiercn commented 1 year ago

@mediabuff thanks for contacting us.

This is not a scenario we support, nor something we plan to address. It seems that you are trying to host newer features (components) inside an older version of the framework. This is not something we plan to address, it does not make sense for Components Webview to take a dependency on ASP.NET Core.

mediabuff commented 1 year ago

Thanks for your quick response. a) >>to host newer features (components) inside an older version of the framework. Well, then what is the right way to host Razor views (*.cshtml) in wpf ?

b) I have shared code in Blazor Server and Wpf Blazor Hybrid. For Server, the start page is _Host.cshml, but for wpf it is index. html. I have quite of a bit of dynamic content in _host.cshml - how do I get that in wpf index.html without hosting Razor views in wpf.

ghost commented 1 year ago

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.