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

[EnC] Unexpected null - file EditSession.cs when updating the body of a method in a nested class when marked with CreateNewOnMetadataUpdate #76989

Open
jeromelaban opened this issue Jan 31, 2025 · 0 comments

Comments

@jeromelaban
Copy link

Version Used: .NET 9.0.102 or 9.0.200-preview.0.25057.12

Steps to Reproduce:

  1. In a console app, build and run the following:

    Console.ReadLine();
    
    public class Test
    {
        public static void Method1() { }
        public static void Method2() { }
    }
    
    [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
    class Test1
    {
        public class Nested
        {
            public void Invoke()
            {
                Test.Method1();
            }
        }
    }
    
    //[global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdate]
    //class Test1
    //{
    //    public class Nested2
    //    {
    //        public void Invoke()
    //        {
    //            Test.Method2();
    //        }
    //    }
    //}
  2. Comment the first Test1 class

  3. Uncomment the second Test1 block

  4. Apply the changes

Diagnostic Id: None

If this is a report about a bug in an analyzer, please include the diagnostic ID and message if possible (e.g. "IDE0030: Use coalesce expression").

Expected Behavior: The update is being applied without an exception.

Actual Behavior: The following error is displayed by the IDE:

System.InvalidOperationException: Unexpected null - file EditSession.cs line 688
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber, String filePath)
   at Microsoft.CodeAnalysis.EditAndContinue.EditSession.MergePartialEdits(Compilation oldCompilation, Compilation newCompilation, IReadOnlyList`1 edits, ImmutableArray`1& mergedEdits, ImmutableHashSet`1& addedSymbols, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.EditAndContinue.EditSession.GetProjectChangesAsync(ActiveStatementsMap baseActiveStatements, Compilation oldCompilation, Compilation newCompilation, Project oldProject, Project newProject, ImmutableArray`1 changedDocumentAnalyses, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.EditAndContinue.EditSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider solutionActiveStatementSpanProvider, UpdateId updateId, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.EditAndContinue.DebuggingSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider activeStatementSpanProvider, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.ExternalAccess.Watch.Api.WatchHotReloadService.GetUpdatesAsync(Solution solution, Func`2 isRunningProject, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.ExternalAccess.Watch.Api.WatchHotReloadService.EmitSolutionUpdateAsync(Solution solution, CancellationToken cancellationToken)

Note that the issue happens because both the inner class name and the body of the Invoke method are changing. If the body does not change and only the class name, the error does not happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant