runtime: TypeLoadException from dynamically-generated assembly; does not occur from the same assembly loaded from disc
Description
While testing the Boo compiler’s System.Reflection.Metadata port, I ran across a very strange error. When creating two assemblies in-memory, A and B, where A is created first and B has a dependency on it, if B attempts to load an Attribute defined on A, it will throw a TypeLoadException. However, if both assemblies are saved to disc and loaded as project references of assembly C, all the types load as expected.
Both assemblies pass ILVerify, and the process works just fine when loaded from disc. This suggests that the problem is not in the assemblies, but rather the runtime. Either that or there’s some obscure corner case with my code generation?
Reproduction Steps
- Clone this commit from the in-progress codegen work.
- Open src\Boo.Core.sln in Visual Studio. Restore NuGet packages and build. (Project “Test” will not build yet. Ignore it.)
- Run the varargs_attribute_external test. Observe
TypeLoadExceptionbeing thrown when it tries to access theVarArgsAttributeclass.
- Grab this zipfile, containing the two assemblies built by this testcase. Plug them in as the broken dependencies on project “Test,” and build it.
- Run Test, which duplicates the basic functionality of the testcase here. See that everything runs as expected.
Expected behavior
In both cases, the same output should be generated.
Actual behavior
Step 5 works as expected, but step 3 crashes.
Regression?
This worked as expected under Framework when generating the assemblies with System.Reflection.Emit.
Configuration
.NET 5, Windows 10, x64
Other information
It would be a lot easier to debug this if TypeLoadException would provide some relevant information regarding what went wrong.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (21 by maintainers)
aaaah. no no it’s not pe builder, it’s assembly manifest. add a correct entry to the assembly table, the AddAssembly method has a version parameter.