gpt4 book ai didi

.net - GetExportedTypes 抛出的 MissingMethodException

转载 作者:行者123 更新时间:2023-12-01 15:14:36 26 4
gpt4 key购买 nike

当我调用 GetExportedTypes 时,我得到了一个 MissingMethodException,代码:

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:

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

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

Reflector 加载这个程序集没有问题:
  • 已在 GAC 注册
  • 它只引用 mscorlib。
  • 我没有构建程序集 - 我的机器上只有这个程序集的 1 个版本。

  • 更新:

    有问题的程序集似乎是使用 Tlbexp.exe 构建的程序集- 这似乎正在产生某种差异。

    最佳答案

    据我所知,只是预期某些程序集会抛出此异常 - GetTypes方法抛出类似的异常 - ReflectionTypeLoadException ,但是这个异常也有 Types属性似乎是已成功加载的类型列表。

    现在我已经修改了我的代码,以便它调用此方法并捕获生成的异常:

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

    它并不漂亮,但它似乎确实有效。

    关于.net - GetExportedTypes 抛出的 MissingMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3509009/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com