Open spoiledsport opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.
Author: | spoiledsport |
---|---|
Assignees: | - |
Labels: | `area-AssemblyLoader-coreclr`, `untriaged` |
Milestone: | - |
I modified the repro to use AssemblyBuilder.DefineDynamicAssembly
(as the AppDomain
API is only available on .NET Framework).
Leaving the repro otherwise as-is I see consistent behavior between both .NET Framework and .NET Core:
TypeResolve
event handler for Bar
Bar
typeBut looking at the repro there seems to be a problem - the Bar
type was never actually created. There's no call TypeBuilder.CreateType
for that type. So I added tb2.CreateType()
after the last line of ilgen2.Emit...
With this change the repro works without any exception (and no event handler is triggered either).
My understanding of the TypeBuilder
API is that one must call CreateType
before actually using the type at runtime. Mono's implementation is probably a bit more permissive. @lambdageek for comments on the Mono's behavior.
When attempting to instantiate a dynamic type hosted in a dynamic assembly from another type residing in another dynamic assembly, do not fire a TypeResolve event. Trying to create the type fail with a TypeLoadException.
This issue is not present on Mono, and the type can be successfully created.
A minimal reproduction code has been included which targets both the full framework and .NET Core.
This seems to be a bug in every .NET runtime I tried up to now. I see similar closed issue #10237
Microsoft.AspNetCore.All 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
TypeResolveBug.cs.txt