我收到抛出的MissingMethodException当我打电话GetExportedTypes,在code:
I'm getting a MissingMethodException thrown when I call GetExportedTypes, the code:
Assembly.LoadFrom(assemblyPath).GetExportedTypes();
例外(名称混淆):
The exception (names obfuscated):
System.MissingMethodException was unhandled Message="Method not found: 'Void Namespace.IMyMethod.MyMethod(UInt32, Namespace.IMyOtherMethod ByRef, UInt32 ByRef)'." Source="mscorlib" StackTrace: at System.Reflection.Assembly._GetExportedTypes() at System.Reflection.Assembly.GetExportedTypes() at ConsoleApplication1.Program.Main(String[] args) in C:\Documents and Settings\jpealing\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 16 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
的异常没有内部异常或其它细节值得一提。
The exception has no inner exception or other details worth mentioning.
是什么原因造成的?我该如何解决这个问题?
What causes this? How can I fix it?
反射器没有问题,加载这个组件:
Reflector has no problems loading this assembly:
- 这是注册在GAC
- 只引用mscorlib中。
- 在我没有建立组装 - 只有1我的机器上版本的程序集
更新:
在问题的组件,似乎是一个组件内置使用的 Tlbexp.exe - 这很可能是这个正在某种差异
The assembly in question appears to be an assembly built using Tlbexp.exe - it seems likely that this is making some sort of difference.
推荐答案据我可以看到它只是预计某些组件抛出此异常 - 的 GetTypes 方法抛出了类似的例外 - ReflectionTypeLoadException ,但此异常也有一个类型中这似乎是被成功加载类型的列表属性。
As far as I can see it is simply expected that certain assemblies throw this exception - the GetTypes method throws a similar exception - ReflectionTypeLoadException, however this exception also has a Types property which appears to be the list of types that were successfully loaded.
现在我已经适应我的code,使其调用此方法,而不是和捕捉由此导致的异常:
For now I have adapted my code so that it calls this method instead and catches the resulting exception:
try ( return assembly.GetTypes(); ) catch (ReflectionTypeLoadException ex) { return ex.Types; }
它不是pretty的,但它似乎工作。
Its not pretty, however it does appear to work.
更多推荐
的MissingMethodException抛出GetExportedTypes
发布评论