C# System.TypeLoadException未处理:无法加载类型,因为该方法没有实现(无RVA)

C# System.TypeLoadException未处理:无法加载类型,因为该方法没有实现(无RVA),c#,reflection,C#,Reflection,我试图通过输入字符串来执行命令。我有以下课程: abstract class ECommand { public static bool TryExecute(string raw, out object result) { string name = raw; //function trigger if (!Config.CommandRegister.ContainsKey(name)) { result = null;

我试图通过输入字符串来执行命令。我有以下课程:

abstract class ECommand {
    public static bool TryExecute(string raw, out object result) {
        string name = raw; //function trigger
        if (!Config.CommandRegister.ContainsKey(name)) {
            result = null;
            return false;
        }

        Type datType = Config.CommandRegister[name];
        var instance = Activator.CreateInstance(datType);
        MethodInfo method = datType.GetMethod("Execute");
        result = method.Invoke(instance, null);

        return true;
    }

    public extern object Execute();
}
字符串和等效类型在字典中的注册方式如下:

public static Dictionary<string, Type> CommandRegister = 
new Dictionary<string, Type> { {"test", typeof(TestECommand)} };     
什么时候叫它

ECommand.TryExecute(source, out res);
我得到以下例外情况:

System.TypeLoadException was unhandled
  HResult=-2146233054
  Message=Could not load type 'Test.ECommand' from assembly 'Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'Execute' has no implementation (no RVA).
  Source=Test
  TypeName=Test.ECommand

我做错了什么?

我认为您混淆了
extern
关键字-它通常用于p/invoke

我想你的意思是
摘要

public abstract object Execute();

我认为您混淆了
extern
关键字-它通常用于p/invoke

我想你的意思是
摘要

public abstract object Execute();

我猜想,当ECommand有一个Execute()的实现时,包含TestECommand的程序集很旧,并且是针对ECommand编译的。我还猜测您已经将ECommand.Execute更改为abstract,删除了实现,而没有重新编译托管teste命令的程序集。如果我的猜测是正确的,重新编译(和清理旧资源)将解决这个问题。(还要确保没有在重新编译时未更新的旧文件引用。)我没有更改代码。所有的东西都在一个项目中,所以我不认为有什么东西会过时?在我进一步的研究中,我也发现了类似的答案,但它们似乎使用了不是最新的库。我猜想,当ECommand有一个Execute()的实现时,您包含TestECommand的程序集很旧,并且是针对ECommand编译的。我还猜测您已经将ECommand.Execute更改为abstract,删除了实现,而没有重新编译托管teste命令的程序集。如果我的猜测是正确的,重新编译(和清理旧资源)将解决这个问题。(还要确保没有在重新编译时未更新的旧文件引用。)我没有更改代码。所有的东西都在一个项目中,所以我不认为有什么东西会过时?在我的进一步研究中,我也发现了类似的答案,但他们似乎使用了不最新的库。