的MissingMethodException抛出GetExportedTypes [英] MissingMethodException thrown by GetExportedTypes

查看:140
本文介绍了的MissingMethodException抛出GetExportedTypes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到抛出的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 ,但此异常也有一个<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.types.aspx"相对=nofollow>类型中这似乎是被成功加载类型的列表属性。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆