-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
I've upgraded a complex .NET Core 2.2 solution to .NET Core 3.0 over the weekend, and I am now running into somewhat random, but completely inexplicable issues when debugging the ASP.NET Core projects.
The complexity of the solution is that there are five "main" ASP.NET Core projects, and one "shared" ASP.NET Core project. The shared project is set as a class library output. It is an ASP.NET Core project so I can work with TypeScript properly, and for base views. I attempted to make a Razor Class Library before but I couldn't get it work, gave up and moved on with my life.
The shared project has some views in a Features folder, in this case _Layout.cshtml
. This view is used by two other main projects.
When I attempt to run the projects from Visual Studio, F5 or CTRL+F5, I am always greeted by this exception:
InvalidOperationException: The layout view '~/Features/_Layout.cshtml' could not be located. The following locations were searched: ~/Features/_Layout.cshtml
The only thing I've found to make the exception go away is to edit the project's file and either comment or un-comment the <AddRazorMvcSupport>true</AddRazorMvcSupport>
property and re-run. Making changes, rebuilding, and debugging after that works fine.
To be honest, I'm not sure if that is a real property, I saw it either in GitHub issue discussion or a SO thread and copied it over and I can't find the link to it anymore. It was part of the Razor SDK. For all I know, commenting or un-commenting anything at random in the project file will fix the issue, I just haven't tested it.
This does not appear to be an issue when the project is published in release mode to IIS. This only appears to be an issue when debugging through Visual Studio.
I cannot manually test using the CLI because I use named URLs for debugging which are required for the app's functionality, and manually running the apps gives it localhost
as the URL.
Looking through the output folder, the shared project's .View.dll
file is there as expected.
To Reproduce
- Using Windows 10, 1903 (forced me into an upgrade on Friday, was 1803 before that)
- Using ASP.NET Core 3.0
- Using Visual Studio 16.3.1
- Create two ASP.NET Core projects.
- Set one to output as a class library, this is the "shared" project now.
- Add a
_Layout.cshtml
file to the shared project. - Add a view to the other "main" project that references the layout from the shared project.
To be honest, I'm not sure if this will reproduce the error. My projects do a lot of other things such as authentication and authorization, etc., that are almost impossible to describe here without writing a book and exposing, potentially, private business logic.
The production server is Windows Server 2019, 1809 on AWS.
The bottom line is that this issue occurred as a result of either upgrading to Visual Studio 16.3 or .NET Core 3.0. This never occurred while I was on Visual Studio 16.2 and .NET Core 2.2.
Expected behavior
I expect the view in the shared project to be found and used, always.
Additional context
Here is the stack trace:
Microsoft.AspNetCore.Mvc.Razor.RazorView.GetLayoutPage(ViewContext context, string executingFilePath, string layoutPath)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
REDACTED.Web.ApplicationUserMiddleware.InvokeAsync(HttpContext context, IApplicationUserServices services) in ApplicationUserMiddleware.cs
+
await Next(context);
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Arex388.AspNetCore.HtmlMinifierMiddleware.InvokeAsync(HttpContext context)
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)