ASP.NET Core 6 Error: InvalidOperationException: A descriptor for '/Pages/Error.cshtml' was not found

I am new to ASP.NET Core 6 Web Applications. I am encountering a problem when I run my web application for first time.

I receive this error:

InvalidOperationException: A descriptor for '/Pages/Error.cshtml' was not found.

I need help to solve this issue.


There is a GitHub issue related to this error message, although the specifics of that particular case will be different. In it, contributor @pranavkm offers the following guidance:

The app references a 6.0 runtime and a 3.1 version of Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (transitively via https://www.nuget.org/packages/Volo.Abp.AspNetCore.Mvc/1.1.2). We recently made a behavior change to Mvc which requires a compatible (6.0 versioned) runtime compilation when that feature is used. Adding a package reference to the 6.0 version gets you past that issue.

 <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0-preview.2.21101.10" />

Mixing package versions (using 3.x or 5.x versioned package with the 6.0 runtime) isn't necessarily always going to work. We anticipate users to update their packages as part of the migration. I can run this by more people in the dev team, but it's unlikely that we will do any additional work here.

Now, obviously, you probably aren't using Volo.Abp—and, by extension, may not be using Razor Runtime Compilation. As a result, the source of your specific error is likely different. But the cause of your error should be the same: One of your dependencies maintains a reference to a legacy 3.x or 5.x package with incompatible code.

By evaluating your stack trace, you should be able to identify the specific culprit—and, hopefully, the developer has included an updated version of their package by now.

If it's due to a downstream dependency, as in the above example, you will need to drill down in the dependency graph on NuGet to find the offending package that relies on the 3.x or 5.x runtime. If that's the case, hopefully there is a newer compatible version, and then you can establish an explicit dependency to the upgraded version via NuGet.

If there isn't a newer compatible version of the offending package, you'll need to contact the vendor, and/or wait for them to release an update for .NET 6.