2010-08-18 32 views
3

我得到当我打电话GetExportedTypes,代码抛出MissingMethodException抛出:MissingMethodException通过GetExportedTypes

Assembly.LoadFrom(assemblyPath).GetExportedTypes(); 

异常(名称混淆):

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: 

异常没有内部异常或其他细节值得一提。

这是什么原因造成的?我该如何解决它?

反射器具有没有问题加载该组件:

  • 它注册在GAC
  • 只引用MSCORLIB。
  • 我没有构建程序集 - 在我的机器上只有1个版本的程序集。

更新:

有问题的组件,似乎是一个装配使用Tlbexp.exe内置 - 这很可能是这是使某种差异。

+0

如果可能,你可以提供整个堆栈跟踪吗? – leppie 2010-08-18 04:48:15

回答

2

至于我可以看到它是简单地预计某些组件抛出此异常 - 在GetTypes方法抛出了类似的例外 - ReflectionTypeLoadException,但是此异常也有这似乎是已成功类型列表中Types属性加载。

现在我已经适应我的代码,以便它调用此方法,而不是和捕获产生的异常:

try 
(
    return assembly.GetTypes(); 
) 
catch (ReflectionTypeLoadException ex) 
{ 
    return ex.Types; 
} 

它不漂亮,但它似乎工作。

0

我见过类似的东西,当我将我的一个项目,以.NET 4

虽然发生在PEVERIFY我的问题,它暗示同样的问题。

如果在较旧的程序集上使用.NET 4,请将安全策略更改回较旧的程序集。

这是MSDN link

+0

'Fraid this is all .Net 3.5 – Justin 2010-08-18 04:58:05

+0

@Kragen:这个铃声响应了原始3.5 RTM中一个影响Rhino mock的bug。 – leppie 2010-08-18 05:03:57

相关问题