我想使用emit动态编译以下两个类的程序集,该程序实际上并未保存成dll,以下这个是保存后的结构
但是将以上程序集引入程序后,在使用
var t = typeof(Orders_11);
Console.WriteLine(t.GetCustomAttributes(typeof(MetadataTypeAttribute), false));
时,提示
System.IO.FileLoadException : 未能加载文件或程序集“test9, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
在 System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
在 System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, ref IntPtr blob, IntPtr blobEnd, ref Int32 namedArgs)
在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
在 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
在 System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
初步分析原因可能是 MetadataTypeAttribute 使用了同一程序集中的另一个类,这里换成 typeof(string) 就没有问题了,请高手指点,谢先!