'Identity MVC Project in .NET 5 upgraded to .NET 6 cannot find Views when deployed to AKS Cluster (Linux)

I am working on upgrading my .NET Identity project from .NET 5 to .NET 6. Currently, everything works flawlessly while the project is in .NET 5 but as soon as I upgrade to .NET 6 and update the NuGet packages that require a dependency change, I start getting the following error after deploying it to aks:

System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/Home/Index.cshtml
/Views/Shared/Index.cshtml
at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()

When Debugging locally, I don't get any of this issues. Also, the errors says it is looking for the 'Index' page but if you manually route to another page, it will throw the same exception. I have searched for similar issues that other people might have upgrading to .NET 6 but at the moment I have not been able to find anyone encountering the same problem.

NOTE: If I rollback to .NET 5, it works without any issues again.

Any help or pointers are appreciated, thanks in advance for any help.

Here is my DockerFile used to build the Docker Container and what it is used in the AKS cluster

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["xxxx/IdentityApp.csproj", "IdentityApp/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
COPY ["xxxx/xxxx", "xxxx/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
COPY ["xxxx/xxxx.csproj", "xxxx/"]
RUN dotnet restore "IdentityApp/IdentityApp.csproj"
COPY . .
WORKDIR "/src/IdentityApp"
RUN dotnet build "IdentityApp.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "IdentityApp.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "IdentityApp.dll"]


Solution 1:[1]

For anyone struggling with a similar scenario. It turned out to be that we had this on the .csproj

<AdditionalFileItemNames>$(AdditionalFileItemNames);Content</AdditionalFileItemNames>

causing an error while building, it would be random so it would only build with the 6.0.100 .NET SDK but have failures at runtime. After removing it, it starting building normally again.

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 Juan P. Garces