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
Razor views not existing after updating from .NET 5 to .NET 6 in Identity.UI #7251
Comments
@Ben555555 thanks for contacting us. Can you provide a minimal repro project that illustrates this issue? |
After digging for hours I found a possible solution or the root of the problem. While building the following message appears. Since it's only a warning I didn't quite give it any attention: 1>CSC : warning CS8785: Generator 'RazorSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.' From another source I found that you get more detailed information by adding the following to the csproj file:
This didn't give me any additional information though, but suddenly the razor views were compiled and also all the route mappings were there! @javiercn @javiercn |
@Ben555555 thanks, that is indeed useful information. Seems that it is a razor-compiler issue, so I'm going to transfer it there. |
@jaredpar is there any way to get the callstack when a source generator fails with an exception? |
@javiercn I can repro it and will take a deeper look later, it looks like there is a
|
@chsienki is the RazorCompiledItemMetadataAttribute with a null value inside the Microsoft.AspNetCore.Identity.UI assembly? |
Ah ok, I think I see what is going on. The crash happens because the razor files inside They don't have a target path because it looks like they aren't supposed to be compiled at all. In the csproj we have <ItemGroup>
<!-- Make sure razor email templates are not pre-compiled during build, only by MiniRazor -->
<Compile Remove="Templates\Email\**" />
<Content Remove="Templates\Email\**" />
<EmbeddedResource Remove="Templates\Email\**" />
<None Remove="Templates\Email\**" />
<AdditionalFiles Include="Templates\Email\*.cshtml" IsRazorTemplate="true" />
</ItemGroup> Presumably that logic removed them from the pre-compilation pipeline, but they're still getting included in the source generator as they're additional files ending |
@javiercn I'm not actually sure how we can fix this, the generator is always going to generate for every Either we need a way of allowing users to exclude files from the generator (a metadata value would be an easy way to do that) or say that you just can't do this and are required to use a different extension for the templates. |
Oh, actually, if we fix the target path issue, it might be as simple as just ignoring anything without a target path. Effectively that says 'the generator targets added this file', and anything else we just ignore. |
Filed #7236 to track not crashing when target path is empty |
@chsienki I've taken a look based on your comments and seems reasonable. |
Is there an existing issue for this?
Describe the bug
After migrating from .NET5 to .NET6 the razor views don't work anymore for Microsoft.AspNetCore.Identity.UI. We use scaffold to setup the identity server razor pages. When I open the Login page "https://localhost:44390/Identity/Account/Login" I get the following exception:
InvalidOperationException: The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration we have looked at it in the following locations:
/Areas/Identity/Pages/Account/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/Account/_LoginPartial.de.cshtml
/Areas/Identity/Pages/Account/_LoginPartial.cshtml
/Areas/Identity/Pages/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/_LoginPartial.de.cshtml
/Areas/Identity/Pages/_LoginPartial.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.de.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.de-CH.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.de.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.cshtml
/Pages/Shared/_LoginPartial.de-CH.cshtml
/Pages/Shared/_LoginPartial.de.cshtml
/Pages/Shared/_LoginPartial.cshtml
/Views/Shared/_LoginPartial.de-CH.cshtml
/Views/Shared/_LoginPartial.de.cshtml
/Views/Shared/_LoginPartial.cshtml.
Microsoft.AspNetCore.Identity.UI.V5.Pages.Internal.Areas_Identity_Pages_V5__Layout.b__43_1()
The listed path "/Views/Shared/_LoginPartial.cshtml" clearly exists. It looks like the views are not even compiled, according to the size of the compiled Dlls.
When I turn on runtime compilation it seems to work. But this won't work after deployment.
builder.AddRazorRuntimeCompilation();
I didn't change anything else, except the .NET version and the corresponding libraries from 5 to 6.
Also what I have noticed is that some routes are not mapped anymore which in the previous version were mapped:
/Identity/Account/Login
/Account/Login <= not mapped anymore
Expected Behavior
The pages razor pages should render as expected.
Steps To Reproduce
No response
Exceptions (if any)
InvalidOperationException: The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration we have looked at it in the following locations:
/Areas/Identity/Pages/Account/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/Account/_LoginPartial.de.cshtml
/Areas/Identity/Pages/Account/_LoginPartial.cshtml
/Areas/Identity/Pages/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/_LoginPartial.de.cshtml
/Areas/Identity/Pages/_LoginPartial.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.de-CH.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.de.cshtml
/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.de-CH.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.de.cshtml
/Areas/Identity/Views/Shared/_LoginPartial.cshtml
/Pages/Shared/_LoginPartial.de-CH.cshtml
/Pages/Shared/_LoginPartial.de.cshtml
/Pages/Shared/_LoginPartial.cshtml
/Views/Shared/_LoginPartial.de-CH.cshtml
/Views/Shared/_LoginPartial.de.cshtml
/Views/Shared/_LoginPartial.cshtml.
Microsoft.AspNetCore.Identity.UI.V5.Pages.Internal.Areas_Identity_Pages_V5__Layout.b__43_1()
.NET Version
6.0.202
Anything else?
No response
The text was updated successfully, but these errors were encountered: