C# dnLib生成的程序集-运行时引发TypeLoadException

C# dnLib生成的程序集-运行时引发TypeLoadException,c#,cil,dnlib,C#,Cil,Dnlib,我正在使用从我正在编写的自定义语言CSASM动态生成MSIL程序集: string absolute=Path.Combine(Directory.GetCurrentDirectory(),forceOutput???$“{asmName}.exe”); ModuledFuser mod=new ModuledFuser(asmName,Guid.NewGuid(),new AssemblyRefuer(new AssemblyNameInfo(typeof(int).Assembly.Get

我正在使用从我正在编写的自定义语言CSASM动态生成MSIL程序集:

string absolute=Path.Combine(Directory.GetCurrentDirectory(),forceOutput???$“{asmName}.exe”);
ModuledFuser mod=new ModuledFuser(asmName,Guid.NewGuid(),new AssemblyRefuer(new AssemblyNameInfo(typeof(int).Assembly.GetName().FullName))){
种类=模块绑定控制台,
RuntimeVersion=“v4.0.30319”//与“CSASM.Core.dll”相同的运行时版本
};
var asm=new AssemblyDefUser($“CSASM_程序{asmName}”,新版本(Version));
asm.Modules.Add(mod);
//为简洁起见,省略了添加属性代码
//将类型添加到模块中,并基于相关CSASM源文件为这些类型构造方法和方法体
构造(mod,source);
mod.Write(绝对);
可执行文件的生成工作正常

但是,当尝试运行此可执行文件时,会抛出下面的
TypeLoadException

System.TypeLoadException: Could not load type 'CSASM.Core.IntPrimitive' from assembly
'CSASM_program_Example, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' due to
value type mismatch.
   at Example.Program.csasm_main()
CSASM\u program\u Example
是生成的可执行文件的程序集名称,
Example.exe

类型
IntPrimitive
实际上位于
CSASM.Core.dll
程序集中,该程序集与生成的可执行文件位于同一文件夹中

由于dnLib周围的文档极度缺乏,我在这里基本上是在黑暗中跌跌撞撞


简而言之,是否存在试图从错误程序集加载类型的原因?
如果是的话,我有没有办法补救


在dnSpy中查看程序集时,会显示引用正确程序集的
TypeRef
s和
MemberRef
s,这使得这种困境更加令人沮丧。

在对dnLib DLL进行了非常彻底的检查后,问题是由于我使用了
导入程序.ImportDeclaringType(Type).ToTypeDefOrRef()
,这导致值类型
TypeSig
s被注册为类类型
TypeSig
s

即使文档说要使用
Importer.ImportDeclaringType(Type)
而不是
Importer.ImportAsTypeSig(Type)
进行方法和字段声明,但您确实不应该使用它