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.

BlazorWebView for WPF not debuggable when blazor code is in a different project

See original GitHub issue

Description

I am unable to run/debug WPF application from Visual Studio when hosting a blazor application from another project because index.html does not exist in the output folder. I want to re-use the blazor project from my web application.

WPF’s BlazorWebView uses PhysicalFileProvider to the folder of the file pointed to by the value of HostPage property. But that file is in another project and is not copied to the WPF project’s output folder. If provide path to that file then the generated isolated css file will not be loaded. It should either be customizable and/or a CompositeFileProvider that uses all paths from the blazor project’s static web assets xml file should be configured if that file exists.

Steps to Reproduce

  1. Extract the attached zip file
  2. Open the solution is Visual Studio
  3. Press F5 to run it

Expected Behavior

The application runs and displays my web page as it would in web browser when the blazor project is run.

Actual Behavior

DirectoryNotFoundException is thrown pointing to BlazorWpf1\BlazorWpf1\bin\Debug\net6.0-windows\wwwroot\

Basic Information

  • Version with issue: 6.0.0-preview.4.21253.5
  • Last known good version: none
  • IDE: Visual Studio 2019
  • Platform Target Frameworks: net6.0-windows
  • Nuget Packages:
    1. Microsoft.AspNetCore.Components.WebView.Wpf (version 6.0.0-preview.4.21253.5)
  • Affected Devices:

Reproduction Link

BlazorWpf1.zip

Workaround

From the source of WPF WebView, I could not figure out any.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Eiloncommented, Dec 15, 2021

Hi, I know this is an older issue now, but I got the repro project working on my machine by doing the following:

  1. Updating NuGet packages to the latest .NET / MAUI versions
  2. Updating the WPF project’s CSPROJ to have <Project Sdk="Microsoft.NET.Sdk.Razor">

The reason that (2) is needed is that the logic for making static web assets such as CSS/HTML/JS available is all part of the Razor SDK. By referencing the SDK, that brings in the MSBuild targets that place files in the correct location in order to be loaded by the system.

If you want a totally custom way of providing static assets, we recently added that feature in this PR: https://github.com/dotnet/maui/pull/3191

Read more comments on GitHub >

github_iconTop Results From Across the Web

using wwwroot from other project in BlazorWebView
I'm trying to build an application using a Blazor Hybrid Webview, which can be run both from a .NET MAUI application as well...
Read more >
Use browser developer tools with ASP.NET Core Blazor ...
Start the Android emulator and navigate to an app page that uses a BlazorWebView. The developer tools console is unavailable from ContentPages ......
Read more >
.NET 6 Brings Blazor WebView Controls to WPF and WinForms
Issues with Razor component types not being visible in the project can be resolved by the usage of an empty partial class for...
Read more >
Debug ASP.NET Core Blazor WebAssembly
This article describes how to debug Blazor WebAssembly with browser developer tools and an integrated development environment (IDE).
Read more >
Blazor on WPF
The new BlazorWebView for WPF works exactly the same way as it does for .NET MAUI apps—it provides an easy way to embed...
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