References from one dynamic assembly to another dynamic assembly sometimes do not result in an AppDomain.TypeResolve event
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
- Which version of .NET is the code running on?
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]
- What OS and version, and what distro if applicable? Windows 10, Windows 11
- What is the architecture (x64, x86, ARM, ARM64)? x64, x86
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.
Issue Details
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
- Which version of .NET is the code running on?
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]
- What OS and version, and what distro if applicable? Windows 10, Windows 11
- What is the architecture (x64, x86, ARM, ARM64)? x64, x86
| Author: | spoiledsport |
|---|---|
| Assignees: | - |
| Labels: |
|
| 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:
- It triggers the
TypeResolveevent handler forBar - Fails to load
Bartype
But 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.
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.