Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HR] Exception while emitting update: System.NullReferenceException #27612

Open
jeromelaban opened this issue Feb 6, 2025 · 2 comments
Open
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@jeromelaban
Copy link

jeromelaban commented Feb 6, 2025

Description

When a specific set of changes are created, a Hot Reload exception may happen as follows:

EmitSolutionUpdate 33.1: 'C:\temp\MauiHRReloadIssue01\MauiHRReloadIssue01.sln'
Found 1 potentially changed document(s) in project MauiHRReloadIssue01 (net9.0-windows10.0.19041.0) 'C:\temp\MauiHRReloadIssue01\MauiHRReloadIssue01.csproj'
Document changed, added, or deleted: 'C:\temp\MauiHRReloadIssue01\MakeMeFail.cs'
Project summary for MauiHRReloadIssue01 (net9.0-windows10.0.19041.0) 'C:\temp\MauiHRReloadIssue01\MauiHRReloadIssue01.csproj': ValidChanges
Emitting update of 'MauiHRReloadIssue01 (net9.0-windows10.0.19041.0)' C:\temp\MauiHRReloadIssue01\MauiHRReloadIssue01.csproj
Exception while emitting update: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.Emit.DefinitionMap.GetPreviousMethodHandle(IMethodSymbolInternal oldMethod, IMethodSymbolInternal& peMethod)
   at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.<CreateDeletedMethodsDefs>g__getDeletedMethodDefs|83_1(ITypeDefinition typeDef, <>c__DisplayClass83_0&)
   at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.<CreateDeletedMethodsDefs>g__recurse|83_0(ITypeDefinition typeDef, <>c__DisplayClass83_0&)
   at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.CreateDeletedMethodsDefs(EmitContext context, SymbolChanges changes)
   at Microsoft.CodeAnalysis.Compilation.SerializeToDeltaStreams(CommonPEModuleBuilder moduleBeingBuilt, DefinitionMap definitionMap, SymbolChanges changes, Stream metadataStream, Stream ilStream, Stream pdbStream, ArrayBuilder`1 updatedMethods, ArrayBuilder`1 changedTypes, DiagnosticBag diagnostics, Func`2 testSymWriterFactory, String pdbFilePath, 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, CompilationTestData testData, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Compilation.EmitDifference(EmitBaseline baseline, IEnumerable`1 edits, Func`2 isAddedSymbol, Stream metadataStream, Stream ilStream, Stream pdbStream, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.EditAndContinue.EditSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider solutionActiveStatementSpanProvider, UpdateId updateId, CancellationToken cancellationToken)

Which seems to be caused by the removal/rename of methods and the previous body replacement with a exception throwing body (this part is expected).

Steps to Reproduce

  • Open this solution in VS 17.12 or 17.13: Issue27612.zip (zip for archives)
  • Rebuild the app (important, build won't do)
  • Launch the app with the debugger
  • Go into the MakeMeFail.vs file and set the top level #if true to #if false
  • Apply the code changes

Link to public reproduction project repository

https://github.com/jeromelaban/MauiIssue-27612

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

No response

Affected platforms

iOS, Windows, Android

Affected platform versions

No response

Did you find any workaround?

This issue may be caused by the fact that the HR workspace is trying to apply changes to a TargetFramework that is not currently being debugged.

Possible workaround:

<Target Name="_VSCleanupOtherTFMsForHR"
          Condition="
			'$(IsImplicitlyTriggeredBuild)' == 'true'
			AND '$(BuildingInsideVisualStudio)'=='true'
			AND ( '$(OutputType)' == 'Exe' OR '$(OutputType)' == 'WinExe' )
			AND '$(DisableVSCleanupOtherTFMsForHR)' != 'false'"
          BeforeTargets="BeforeBuild">

      <ItemGroup>
          <_HeadsToDelete Include="$(BaseIntermediateOutputPath)\**\$(AssemblyName).dll" Exclude="$(IntermediateOutputPath)\$(AssemblyName).dll" />
      </ItemGroup>

      <Message Importance="low" Text="Deleting intermediate assemblies for HR: @(_HeadsToDelete)" />

      <Delete Files="@(_HeadsToDelete)" />

      <ItemGroup>
          <_HeadsToDelete Remove="@(_HeadsToDelete)" />
      </ItemGroup>
  </Target>

Relevant log output

@jeromelaban jeromelaban added the t/bug Something isn't working label Feb 6, 2025
@jeromelaban
Copy link
Author

Also reported as a performance issue in VS Community.

@Ying-6
Copy link

Ying-6 commented Feb 7, 2025

This issue has been verified using Visual Studio 17.13 Preview 5.0 (9.0.30 & 9.0.22 & 9.0.0). Can repro this issue on Windows & Android platform.

@jsuarezruiz jsuarezruiz added the area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging label Feb 7, 2025
@jsuarezruiz jsuarezruiz added this to the .NET 9 Servicing milestone Feb 7, 2025
mergify bot pushed a commit to unoplatform/uno that referenced this issue Feb 7, 2025
jeromelaban added a commit to unoplatform/uno that referenced this issue Feb 7, 2025
mergify bot pushed a commit to unoplatform/uno that referenced this issue Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants