System.TypeLoadException - 从程序集***中***类型的方法获取_***没有实现的时候?

Gbp*_*bps 5 c# typeloadexception reference inject

我使用程序Reflexil将可执行文件Foo1.exe中的引用注入到名为Foo2.dll的外部程序集中.

在Foo1.exe中,有一个名为Bar的类.

在Foo2.dll中,有一个接口IBar,它正确实现了Bar的所有字段和方法.

我已经使用Reflexil在Foo1.exe中为Bar提供了Foo2.dll中的IBar接口.

加载Foo1.exe时,它会找到位于应用程序目录中的Foo2.dll并加载它,但它会抛出System.TypeLoadException,并显示以下错误消息 Method 'get_***' in type 'Foo1.Bar' from assembly 'Foo1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

我已经通过相同的错误信息前面的问题读取(TypeLoadException说"不执行",但它的实现),但我一直无法弄清楚如何正确地实现修复时,我没有任何编译检查Foo1.exe.

谢谢你的帮助!

小智 5

在以下情况下,我收到了相同的错误消息:A.dll 依赖于 B.dll,B.dll 依赖于 C.dll 并且未找到 C.dll。在我的情况下,A.dll 包含从位于同一程序集和同一 dll - A.dll 中的抽象类 C1 派生的类 C2。C1 派生自 B.dll 的 C0 类。C0 有抽象属性和抽象 getter 方法,C1 有这个属性的实现,但问题是属性的 getter 的返回类型是在缺少的库 C.dll 中定义的。最后,它会导致错误消息“来自程序集 'A,版本 = 1.0.0.0,文化 = 中性,PublicKeyToken = xxxx' 的类型为 'C2' 的方法 'get_Prop' 没有实现。” 这在这种情况下是无关紧要的。简而言之,源代码如下所示:

C.dll:

namespace C {
  public enum PropType {V1 = 0, V2 = 1, ...}
}
Run Code Online (Sandbox Code Playgroud)

B.dll:

using C;
namespace B {
  public abstract class C0 {
    ...
    public abstract C.PropType Prop {get;}
  }
}
Run Code Online (Sandbox Code Playgroud)

A.dll:

using C;
using B;
namespace A {
  public abstract class C1 : B.C0 {
    ...
    // Getter implementation
    public override C.PropType Prop { get {return C.PropType.V1;}}
  }
}

using C;
using B;
namespace A {
  // Class implementation
  public class C2 : C1 {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

所以解决办法是在安装中添加C.dll。