dotnet / dotnet/maui

[Apple mobile] dotnet watch: XAML edits do not update the UI, C# edits crash with a Roslyn EnC NullReferenceException

Open
#35,928 5 comments 1 reaction 2 assignees Claimed by @matouskozak View on GitHub
area-tooling platform/ios platform/macos
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

Running `dotnet watch` on Apple targets fails in a few different ways depending on the edit type and the target.

Failures:
- **iOS simulator, XAML edit:** the terminal logs "changes applied" but the running UI is never updated. Silent no-op.
- **iOS simulator, C# edit:** a method-body edit throws a NullReferenceException inside the Roslyn EnC delta emit (`DefinitionMap.GetPreviousMethodHandle`), and the edit is not applied.
- **iOS device and Mac Catalyst, any edit:** the app launches and then immediately aborts at startup (signal 6) because the dotnet-watch `DotNetDeltaApplier` startup hook can't be loaded inside the deployed `.app`. Its path points at the SDK on the host, which isn't present/loadable in the app sandbox (FileNotFound on device, Access denied on Catalyst).
- On Mono, these scenarios crash too

To reproduce: run `dotnet watch` for the target and wait until the app is running. On the iOS simulator, edit a label in `MainPage.xaml` and save (UI doesn't update), then edit a method body in `MainPage.xaml.cs` and save (NullReferenceException). On `net11.0-ios` (device) or `net11.0-maccatalyst`, run `dotnet watch` and the app aborts at startup before you can edit anything.

### Versions
```
SDK: 11.0.100-preview.6.26315.102
MAUI: 11.0.0-preview.6.26313.4/11.0.100-preview.6
ms-dotnettools.csharp version: 2.143.56
ms-dotnettools.csdevkit: version: 3.21.208
ms-dotnettools.dotnet-maui: version: 1.16.53
```

### Logs
iOS simulator — XAML edit (silent no-op):
```
[Hot Reload] changes applied
(no visible UI update on the simulator)
```
iOS simulator — C# edit (NullReferenceException; caught, so no dump is produced — the stack is the signal):
```
dotnet watch ❌ An unexpected error occurred: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.Emit.DefinitionMap.GetPreviousMethodHandle(IMethodSymbolInternal oldProperty, IMethodSymbolInternal& peMethod)
at Microsoft.CodeAnalysis.Emit.DefinitionMap.GetDeletedSynthesizedMethods(IMethodSymbolInternal oldMethod, ImmutableArray`1 currentLambdas)
at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.g__addDeletedClosureMethods|87_2(IMethodSymbolInternal oldMethod, ImmutableArray`1 currentLambdas, ImmutableArray`1 orderedLambdaRuntimeRudeEdits, <>c__DisplayClass87_0&, <>c__DisplayClass87_1&)
at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.g__getDeletedMemberDefs|87_1(ITypeDefinition typeDef, <>c__DisplayClass87_0&)
at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.g__recurse|87_0(ITypeDefinition typeDef, <>c__DisplayClass87_0&)
at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.CreateDeletedMemberDefs(EmitContext context, SymbolChanges changes)
at Microsoft.CodeAnalysis.Emit.CommonPEModuleBuilder.CreateDeletedMemberDefinitions(DiagnosticBag diagnosticBag)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CompileMethods(CommonPEModuleBuilder moduleBuilder, Boolean emittingPdb, DiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Compilation.Compile(CommonPEModuleBuilder moduleBuilder, Boolean emittingPdb, DiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Emit.EmitHelpers.EmitDifference(CSharpCompilation compilation, EmitBaseline baseline, IEnumerable`1 edits, Func`2 isAddedSymbol, Stream metadataStream, Stream ilStream, Stream pdbStream, EmitDifferenceOptions options, CompilationTestData testData, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Compilation.EmitDifference(EmitBaseline baseline, IEnumerable`1 edits, Func`2 isAddedSymbol, Stream metadataStream, Stream ilStream, Stream pdbStream, EmitDifferenceOptions options, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.EditAndContinue.EditSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider solutionActiveStatementSpanProvider, UpdateId updateId, ImmutableDictionary`2 runningProjects, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.EditAndContinue.DebuggingSession.EmitSolutionUpdateAsync(Solution solution, ImmutableDictionary`2 runningProjects, ActiveStatementSpanProvider activeStatementSpanProvider, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.ExternalAccess.HotReload.Api.HotReloadService.GetUpdatesAsync(Solution solution, ImmutableDictionary`2 runningProjects, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.CompilationHandler.GetManagedCodeUpdatesAsync(HotReloadProjectUpdatesBuilder builder, Func`3 restartPrompt, Boolean autoRestart, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.Program.RunAsync()
```
iOS device / Mac Catalyst — app aborts at startup (startup hook fails to load):
```
Unhandled exception. System.ArgumentException: Startup hook assembly '/usr/local/share/dotnet/sdk/11.0.100-preview.6.26315.102/DotnetTools/dotnet-watch/11.0.100-preview.6.26315.102/tools/net11.0/any/hotreload/net10.0/Microsoft.Extensions.DotNetDeltaApplier.dll' failed to load. See inner exception for details.
---> System.IO.FileNotFoundException: Could not load file or assembly '...Microsoft.Extensions.DotNetDeltaApplier.dll'. The system cannot find the file specified. (Mac Catalyst variant: System.IO.FileLoadException: ... Access is denied.)
at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook)
at System.StartupHookProvider.ManagedStartup(Char* pDiagnosticStartupHooks, Exception* pException)
App terminated due to signal 6.
dotnet watch ❌ [DogfoodApp-p6 (net11.0-ios)] Exited with error code 1
```
Screenshots: TBD.

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.