-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix TypeBuilder.DefineMethodOverride validation error #101246
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection |
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
...es/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderAPIsTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
If you would like to keep going on the IsAssignableFrom implementation, you may want to steal some non-ref emit tests cases for it. The assignability (for generics in particular) is a complicated algorithm. I am not sure whether it is worth it to try to implement it just for the validation. |
For the record: we end up removing |
* Fix DefineMethodOverride validation error * Add more checks and tests * Remove DefineMethodOverride validations that not exist in RuntimeTypeBuilder
On
TypeBuilder.DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)
TypeBuilderImpl
validates if themethodInfoBody
could override themethodInfoDeclaration
runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs
Lines 323 to 325 in 3725bfc
ValidateBaseType
checks if theTypeBuilderImpl
implements the declaring type of themethodInfoDeclaration
runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs
Lines 345 to 351 in 3725bfc
In case the base type is constructed generic type that involves TypeBuilder (i.e. instance of
TypeBuilderInstantiation
) it throws asIsAssignableFrom
is not implemented.Static
TypeBuilder.GetMethod(...)
only allow getting declared methods, so just comparing the instance with the type should be enough forTypeBuilderInstantiation
Fixes #100537