ILGenerator
does not properly handle function pointers
#111003
Labels
ILGenerator
does not properly handle function pointers
#111003
Description
When using the new
PersistedAssemblyBuilder
introduced in .NET 9 and trying to load a field whose type is a function pointer, invalid IL gets generated, causing the application to crash with aSystem.MissingFieldException
when executed.(On another note, is there currently a way of generating such fields using
ILGenerator
? How do you get aType
object for a function pointer at runtime?)Reproduction Steps
The following code reproduces the problem in .NET 9. It doesn't produce a working executable by itself since I did not set the entry point, so to execute code from the generated assembly, you would need to reference it by some other assembly.
Expected behavior
The following IL is generated as the method body for
Test::Main()
when running under .NET Framework 4.8.1:The generated application runs correctly and prints
5
.Actual behavior
The following IL is generated when running under .NET 9:
The
ldsfld
instruction, instead of correctly using a function pointer as the field type, generates some garbage type (as is displayed by ildasm).When executed, the following exception is thrown:
Regression?
API was newly introduced with .NET 9. Works fine in .NET Framework 4.8.1.
Known Workarounds
Don't know of any.
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: