Sami
Sami

Reputation: 2110

Views not found after migrating to .NET 6

I migrated an ASP.NET CORE MVC project from .NET Core 2.1 to .NET 6.

After making relevant changes, the project compiles and starts seemingly OK, but the views aren't found.

Root path is set app.Environment.ContentRootPath = Directory.GetCurrentDirectory(); and the path to views seems to be correct. This is the error message that follows:

enter image description here

The Login.cshtml is in /Views/Account folder, and Build Action is set to Content.

Upvotes: 5

Views: 5925

Answers (6)

Aqua Cat
Aqua Cat

Reputation: 39

For me, the issue was that I had recently installed the latest SDK (7.0.401) but it was not compatible with the version of visual studio I was running. Any website i published would display the view not found error. Uninstalling the SDK resolved the issue.

Upvotes: 0

Dumber_Texan2
Dumber_Texan2

Reputation: 978

@OIbuoye answer worked for me. I also had to add the following to my Startup.cs. This was for a Web API that also has some Views for confirmation pages, errors pages etc...

services.AddControllersWithViews();

Upvotes: 0

Zhou Wei
Zhou Wei

Reputation: 51

For my case, it worked after removing the package of Microsoft.AspNetCore.Mvc 2.2.0. Not sure why this version was still siting in the project after migrating from Net 5 to 6.

Upvotes: 4

OIbuoye
OIbuoye

Reputation: 309

I had the same issue after migrating to .Net 6, and this is the solution that works for me. I checked the list of packages that I have and saw that Microsoft.AspNetCore.Razor.Design outdated version was still part of the project, then I removed it and the solution started working perfectly.

enter image description here

Upvotes: 8

Sami
Sami

Reputation: 2110

Found a solution.

An outdated Razor package messed up the pipeline somehow. I'm not sure why.
Removing the Razor package solved the issue.

Upvotes: 1

Sabbir Islam Mukdo
Sabbir Islam Mukdo

Reputation: 167

your account folder maybe missing in areas like enter image description here

if it is ok then in Startup.cs

in this method public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

paste this code

  app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });

Upvotes: 2

Related Questions