Skip to content

dotnet watch doesn't restart server on lambda return type change #48515

@denis-kralj-codesignal

Description

@denis-kralj-codesignal

SDK version

9.0.203

Environment

MacOS 15.4
Apple M4

Reproduction

  1. Call dotnet new web
  2. Call dotnet watch run --non-interactive and open the local server in a browser
  3. change the return type of the default / GET handler (e.g. from app.MapGet("/", () => "Hello World!"); to app.MapGet("/", () => 1); and save the file
  4. refresh the page

Expectation

Step 3 detects the change as a "rude edit" and restarts the application, step 4 shows the new output in the browser

Reality

Step 3 detects the edit and writes this output to the console:

dotnet watch ⌚ File updated: ./Program.cs
dotnet watch 🔥 [dotnet (net9.0)] Hot reload succeeded.

Step 4 fails and the console gets this error message:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.Runtime.CompilerServices.HotReloadException: Attempted to invoke lambda or local function with an unsupported change made while the application is running: /Users/denis/git/dotnet/Program.cs(4,17): error ENC0054: Changing the return type of lambda requires restarting the application.
         at Program.<>c.<<Main>$>b__0_0()
         at lambda_method1(Closure, Object, HttpContext)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Additional info

This behavior was behaving in line with expectations on SDK version 6.0.400, even without the --non-interactive flag

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions