dotnet / dotnet/aspnetcore

The "developer exception page" stops appearing after editing a Razor view with `dotnet watch run`

Open
#65,505 1 comment 0 reactions 0 assignees View on GitHub
area-commandlinetools
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Visual Studio 2026
ASP.NET 10.0.3

If you are using `app.UseDeveloperExceptionPage()` in an MVC application, and you start your application with `dotnet watch run`, the "developer exception page" will stop appearing if you modify a Razor view.

The following is the exception message that stops the developer exception page from appearing:

```
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[3]
An exception was thrown attempting to display the error page.
System.TypeLoadException: Could not resolve type 'AspNetCoreGeneratedDocument.Views_Home_Index+d__0#1' in assembly 'MyWebApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at System.Reflection.TypeNameResolver.GetType(String escapedTypeName, ReadOnlySpan`1 nestedTypeNames, TypeName parsedName)
at System.Reflection.TypeNameResolver.Resolve(TypeName typeName)
at System.Reflection.TypeNameResolver.GetTypeHelper(Char* pTypeName, RuntimeAssembly requestingAssembly, Boolean throwOnError, Boolean requireAssemblyQualifiedName, IntPtr unsafeAccessorMethod)
at System.Reflection.CustomAttribute.g____PInvoke|30_0(QCallModule __pModule_native, ObjectHandleOnStack __type_native, ObjectHandleOnStack __pCtor_native, IntPtr* __ppBlob_native, IntPtr __pEndBlob_native, Int32* __pcNamedArgs_native, ObjectHandleOnStack __instance_native)
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element)
at Microsoft.Extensions.StackTrace.Sources.StackTraceHelper.TryResolveStateMachineMethod(MethodBase& method, Type& declaringType)
at Microsoft.Extensions.StackTrace.Sources.StackTraceHelper.GetMethodDisplayString(MethodBase method)
at Microsoft.Extensions.StackTrace.Sources.StackTraceHelper.GetFrames(Exception exception, AggregateException& error)
at Microsoft.Extensions.StackTrace.Sources.ExceptionDetailsProvider.GetStackFrames(Exception original)
at Microsoft.Extensions.StackTrace.Sources.ExceptionDetailsProvider.GetDetails(Exception exception)+MoveNext()
at Microsoft.AspNetCore.Diagnostics.RazorViews.ErrorPage.ExecuteAsync()
at Microsoft.Extensions.RazorViews.BaseView.ExecuteAsync(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
```

### Expected Behavior

`dotnet watch run` should not disable the "developer exception page" after a Razor view is modified.

### Steps To Reproduce

1. Open Visual Studio 2026 and click "Create a new project".
2. Select "ASP.NET Core Web App (Model-View-Controller)" and click "Next".
3. Give your application a name and click "Next".
4. Ensure ".NET 10.0 (Long Term Support)" is selected and click "Create".
5. In the newly created project, open `Program.cs` and ensure `app.UseDeveloperExceptionPage()` is being called.
6. In `/Views/Home/Index.cshtml`, throw an exception somewhere on the page.
7. Open a new command prompt, enter the following command (modify it so the path to your .csproj file is correct), and press Enter:

```
cmd /c"set ASPNETCORE_ENVIRONMENT=Development&&set DOTNET_WATCH_SUPPRESS_BROWSER_REFRESH=1&&set ASPNETCORE_URLS=http://localhost:8080&&dotnet watch run --project "C:/Dev/MyWebApplication/MyWebApplication/MyWebApplication.csproj" --no-launch-profile"
```

8. Open a browser and visit `http://localhost:8080`. The developer exception page should successfully appear.
9. Go back to `/Views/Home/Index.cshtml`, and change the exception message. Remember to save.
10. Go back to your browser, and refresh the page. The developer exception page will fail to appear.
11. Look at your command prompt window to see the exception that is stopping the developer exception page from appearing.

![Image](https://github.com/user-attachments/assets/30462f32-32fb-4590-b14e-7db7b2707606)

### .NET Version

10.0.3

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.