- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.2k
          [release/9.0] Fix invalid handle bug happening when TypeBuilder type used in exception catch clause
          #106704
        
          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
Conversation
| Note regarding the   | 
    
      
        1 similar comment
      
    
  
    | Note regarding the   | 
| Tagging subscribers to this area: @dotnet/area-system-reflection-emit | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI some unrelated errors in Build Analysis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this is green, it's approved for merge into RC2 as it's a bug in a new feature in .NET 9.
| /ba-g no failure related to PR or unknown FYI: @carlossanlop | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M2 approved
Backport of #106665 to release/9.0
/cc @buyaa-n
Customer Impact
This is found while reviewing
PersistedAssemblyBuilderimplementation entirely. When newly createdTypeBuilderinstance is used as exception type, whenILGenerator.BeginCatchBlock(Type? exceptionType)calledILGeneratorwill throw because theTypeBuildertoken is invalid, it works fine when existing exception types used.Root cause:
A newly created
TypeBuildertoken is not valid whenILGenerator.BeginCatchBlock(Type? exceptionType)called and the token will not be populated properly until the assembly saved into a file or stream.Solution
Instead of adding exception handler blocks directly into the
ControlFlowBuilderinstance, now collecting them into a list and adding them to theControlFlowBuilderduring Save where all tokens will have populated properly.Regression
It is a bug in a new PersistedAssemblyBuilder added in .NET 9
Testing
A unit test added that reproes the issue
Risk
Low, the fix is straight forward and clean, should not cause a regression
Side note
No new API added with the PR, instead if removed an overriden API from ref that is not needed to be overriden