Forum Discussion

Hammad_ul_haq's avatar
Hammad_ul_haq
Copper Contributor
Feb 16, 2024

.NET 8.0.2 Update Causes ASP.NET Core MVC 'Index View Not Found' Error

Hello everyone,

 

I recently updated to .NET https://github.com/dotnet/core/blob/main/release-notes/8.0/8.0.2/8.0.2.md?WT.mc_id=dotnet-35129-website and encountered an issue with my ASP.NET Core MVC application. After the update, the application began throwing an error related to the 'Index' view not being found. This issue was not present prior to the update.  

 

An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml

 

This error is generated by the Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware and specifically indicates that the MVC framework is unable to locate the 'Index.cshtml' file in both the 'Home' and 'Shared' directories, where it traditionally searches for views.

 

I've verified the existence of the 'Index.cshtml' file in the correct location and ensured that the routing configurations are set up correctly. This setup was working seamlessly before the update to .NET 8.0.2.

Update: I was able to resolve this issue by uninstalling the .NET 8.0.2 updates. After reverting to the previous version, the application started working as expected without any errors. It appears that the .NET 8.0.2 update may have introduced a change or incompatibility affecting the way ASP.NET Core MVC applications locate views.  

 

 

6 Replies

  • plancili's avatar
    plancili
    Copper Contributor

    Hi, this might be a late response but hopefully it can resolve this issue for others as it did for me.

    In your project, make sure that the *.cshtml file has its build action: Content.

     

    Best regards.

  • ArjenDenHartog's avatar
    ArjenDenHartog
    Copper Contributor

    Hammad_ul_haq 

    I also had this problem (sdk version 8.0.203)
    Updating to the latest sdk (https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-8.0.302-windows-x64-installer) fixed the problem.

     

     

  • abusufyan_14's avatar
    abusufyan_14
    Copper Contributor

    Hammad_ul_haq I'm also facing the same problem even when I have created fresh projects all projects give me the same error. 

     

    I found a solution was installing the Nuget Package "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" and then in my Program.cs I appended builder.Services.AddControllersWithViews() with. AddRazorRuntimeCompilation() so it looks like "builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();"

    But it should be a proper fix from Microsoft in this version instead of doing some manual work especially when we create a fresh new project.

    • LeoStefano's avatar
      LeoStefano
      Copper Contributor
      Thanks a lot, worked for me.

      Add Nuget package
      <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.4" />

      and at program.cs:
      builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
      • DavideBellone's avatar
        DavideBellone
        Copper Contributor
        Have you also replaced
        app.MapRazorPages();
        with something else?
    • progpow's avatar
      progpow
      Copper Contributor
      Thank you very much, this helped!

Resources