-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
WPF XAML file can't see types generated by Razor Source Generator #4421
Comments
Some more helpful info from the email thread: It looks like you might be running into some issues related to a breaking change that we made recently in the Razor compiler (see aspnet/Announcements#459). Previously, the Razor compiler produced a separate AppName.Views.dll assembly that contained the compiled view types in an application as public classes under the AspNetCorenamespace. Now, the Razor compiler produces a single AppName.dll that contains the compiled view types as internal sealed classes under the AspNetCoreGenerated namespace. My hunch is that this change is causing the problem that you see here. It's likely that your implementation will work in .NET 6 Preview 2 and earlier. Our current model of compiling the views into a single assembly as internal types is in place to support some build improvements and hot reload so we'll need to sort out a solution for this moving forward. |
Actually WPF XAML cannot see types generated by other "source generators" too. For example, the resource designer classes generated by VocaDb.ResXFileCodeGenerator cannot be used in WPF XAML file. |
I opened #6535 which should fix the issue. A temporary workaround would be to add |
Problem description:
In .NET 6 we are enabling authoring of WPF apps in a "Blazor Desktop" scenario where Blazor web UI (HTML+CSS) is hosted in a web view in a WPF app. Such projects contain a mix of XAML (WPF), Blazor/Razor (HTML+CSS), and other code artifacts (C#, etc.). This is done with a new
<BlazorWebView ... />
WPF control being built by the ASP.NET team.The XAML compiler, however, is unable to see the types generated by the Razor Source Generator. (Note: Using a source generator is new for Blazor in .NET 6; previously it was done in other ways).
For the WPF BlazorWebView control we’d like to support a XAML syntax like this to specify a Razor component to load:
Where
local:Main
is a class that is generated by the Razor compiler as part of the project’s compilation. There is a fileMain.razor
that generates a type Main in the same namespace. The Razor-generated class is visible from C# code, but the XAML compiler is unable to find.From @captainsafia in an email thread:
Actual behavior:
In VS Intellisense you can see the Razor-generated types (good):
But when you try to compile the app, the XAML compiler can't see the same type anymore (bad):
Expected behavior:
The XAML compiler should be able to see the Razor generated types and compile.
Minimal repro:
See repro app here: https://github.com/Eilon/WPFXamlRazorGeneratorBug
To see just the relevant code, look at this commit: Eilon/WPFXamlRazorGeneratorBug@b500285
MainWindow.xaml.cs
un-comment the line at the bottom of the fileWorkarounds:
There are workarounds for this issue:
partial class Index {}
.*.razor
) to a Razor Class Library so that all the Razor-generated types are available prior to the XAML compiler running, thus enabling it to "see" all the types.cc @captainsafia @danroth27
The text was updated successfully, but these errors were encountered: