dotnet / dotnet/sdk

NullReferenceException in ApplyManagedCodeUpdates when running dotnet or aspire watch against Aspire AppHost

Open
#50,156 4 comments 0 reactions 0 assignees View on GitHub
Area-Watch needs-info
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I get the error below when attempting to dotnet watch or aspire run --watch --debug an AppHost with a Blazor WASM project. While it may seem like a minor issue, this really could force a large project that I really want to use Blazor+Aspire for onto Angular. I have tried:
* Adding . this just results in it being loaded twice
* `dotnet dev-certs https --trust` This was already done but I did again, and confirmed the cert was trusted.
* Disabling auto-save in VSCode
* Updating to dotnet SDK latest (9.0.304) and aspire latest (9.4)
* Both Mac and Windows have same behavior
* both dotnet watch and aspire run --watch --debug show same stack trace
* Running dotnet watch on the individual projects (ASP.NET API and ASP.NET Blazor WASM) does not exhibit this behavior.

I can run on the individual projects, but then lose the benefits of Aspire! This [aspnetcore ticket seems related](https://github.com/dotnet/aspnetcore/issues/37462), but since this is only happening when aspire is involved, I'm opening ticket here.

### Expected Behavior

No error. Changing files in either API or Blazor project results in HMR and blazor app refreshes.

### Steps To Reproduce

https://github.com/danroot/Spike.AspireWatchIssue I wrote a minimal repro here, but am getting a different error and behavior. There, dotnet watch won't start at all. That said, I have to think the errors are related

### Exceptions (if any)

```
dotnet watch ⌚ File updated: /Users/MyName/Code/MyCompany.RetailPortal/MyCompany.RetailPortal.WebUI/Pages/Customers/CustomersList.razor
dotnet watch 🔥 [MyCompany.RetailPortal.Api (net9.0)] Hot reload succeeded.
dotnet watch 🔥 [MyCompany.RetailPortal.WebUI (net9.0)] Hot reload succeeded.
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
dotnet watch ⌚ [MyCompany.RetailPortal.WebUI (net9.0)] Exited
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
dotnet watch ⌚ [MyCompany.RetailPortal.Api (net9.0)] Exited
dotnet watch ⌚ [MyCompany.RetailPortal.AppHost (net9.0)] Exited
dotnet watch ❌ System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.Watch.BlazorWebAssemblyDeltaApplier.ApplyManagedCodeUpdates(ImmutableArray`1 updates, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.BlazorWebAssemblyHostedDeltaApplier.ApplyManagedCodeUpdates(ImmutableArray`1 updates, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.CompilationHandler.<>c__DisplayClass19_0.<b__2>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.DotNet.Watch.CompilationHandler.HandleManagedCodeChangesAsync(Func`3 restartPrompt, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred
```

### .NET Version info

danielroot@MacBookPro Spike.AspireWatchIssue % dotnet --info
.NET SDK:
Version: 9.0.304
Commit: f12f5f689e
Workload version: 9.0.300-manifests.407ced12
MSBuild version: 17.14.16+5d8159c5f

Runtime Environment:
OS Name: Mac OS X
OS Version: 15.3
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/9.0.304/

.NET workloads installed:
[wasm-tools]
Installation Source: SDK 9.0.300
Manifest Version: 9.0.8/9.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.workload.mono.toolchain.current/9.0.8/WorkloadManifest.json
Install Type: FileBased

[maui]
Installation Source: SDK 9.0.300
Manifest Version: 9.0.82/9.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/9.0.100/microsoft.net.sdk.maui/9.0.82/WorkloadManifest.json
Install Type: FileBased

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.8
Architecture: arm64
Commit: aae90fa090

.NET SDKs installed:
6.0.301 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.401 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
8.0.203 [/usr/local/share/dotnet/sdk]
8.0.407 [/usr/local/share/dotnet/sdk]
9.0.100 [/usr/local/share/dotnet/sdk]
9.0.202 [/usr/local/share/dotnet/sdk]
9.0.300 [/usr/local/share/dotnet/sdk]
9.0.304 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
x64 [/usr/local/share/dotnet/x64]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

### Anything else?

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.