'The default Identity UI layout requires a partial view '_LoginPartial' error ASP.NET Core 6.0
So. I created a fresh new project with Visual Studio Pro 2019 (v16.11.9) using the model ASP.NET Core with Angular. I set the authentication option to Individual User Accounts.
I got a working scaffolded project with Angular 8, ASP.NET Core 3.1 (didn't dig in why those versions, just accepted the fact), Entity Framework and Identity, which is exactly what I want except for the frameworks versions. I want to work with the latest, so Angular 13 and ASP.NET Core 6.0.
So here I go, upgrading my Angular version by version, checking at each step of the way if the app still works. Got to Angular 13, no identified problem, authentication works fine.
I then follow the very complicated (being ironic here) Microsoft tutorial to update your .NET Core version: Migrate from ASP.NET Core 3.1 to 6.0 and update the .csproj. And boom, when I try reaching the part of the app protected by the auth, I get the following error:
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.cshtml /Areas/Identity/Pages/_LoginPartial.cshtml /Areas/Identity/Pages/Shared/_LoginPartial.cshtml /Areas/Identity/Views/Shared/_LoginPartial.cshtml /Pages/Shared/_LoginPartial.cshtml /Views/Shared/_LoginPartial.cshtml.
Knowing that, the file it says it cannot find is there.
When I access my app, all seems fine. It's just as I click on Fetch Data, the guarded part of the app, that I get this error.
I decided to upgrade all my dependencies to their v6 counterparts. Same error.
I then dug into this Microsoft article: What's new in ASP.NET Core 6.0 that let me know they migrated the IdentityServer from IdentityServer4 to Duende. I changed the namespace. But it never fixed my app.
We're talking default app from Microsoft that stops working without me mingling with any code, just versioning up the frameworks.
I'm very stuck here and dumbfounded on how this could happen and why nobody ever reported that bug. I can't possibly be the only one wanting to work with latest versions of frameworks but also wanting to take advantage of VS built-in project creator?
Can anyone please help me fix this?
Solution 1:[1]
We could solve the problem by adding the following to the csproj file:
<PropertyGroup>
<UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>
The reason to add this was the following message I got during the build: 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 adding this property group could give more detailed information, but instead it solved the views from not getting compiled: https://developercommunity.visualstudio.com/t/vs-2022-mvc-core-does-not-generate-precompiled-vie/1577269#T-N1578977
It's still not clear if this is a good and final solution. You can follow my discussion with the .net team here: https://github.com/dotnet/aspnetcore/issues/41277
Solution 2:[2]
You could get the said error when you move the folder where _LoginPartial is located, the corresponding view will not be found.
If you reference partial view by its name without extension then it will look in the following locations.
/Areas/<Area-Name>/Views/<Controller-Name>
/Areas/<Area-Name>/Views/Shared
/Views/Shared
/Pages/Shared
I found that you could try to use Areas in ASP.NET Core.
Reference: How to move Areas folder to subfolder in DotNet Core with mvc
Solution 3:[3]
Sounds like the file has either been moved or not linked correctly.
I would follow this to scaffold the identity again: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-6.0&tabs=netcore-cli
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Snaketec |
Solution 2 | Deepak-MSFT |
Solution 3 | elefint |