我得到一个System.TypeLoadException在我的代码与下面的描述:System.TypeLoadException:未能加载类型“System.Func`2”
Could not load type 'System.Func`2' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
这里基本上是我在做什么错误附近,SANS的try-catch和其他的东西,这是不必不可少的逻辑:
// assembly is an Assembly object
// derived is of type Derived, which is declared in assembly
// this line works fine
derived = assembly.CreateInstance(derivedClassName, true) as Base;
// this is fine
derived.Foo();
// Exception happens here
derived.Bar();
这里是基地的基础知识:
public abstract class Base : SomeOtherClass
{
protected Base() : base() {}
public void Foo()
{
// do stuff
}
}
这里是派生的基本知识:
public class Derived : Base
{
// overrides SomeOtherClass.Foo(), which is the only abstract method
protected override void Foo()
{
// do stuff
}
}
什么是你的环境?这是一个桌面应用程序? Windows商店/运行时应用程序? Web应用程序?您的应用定位了哪个版本的.net框架? – Tim
定义了Bar()吗? –
你们是在正确的轨道上。 “衍生”和“基础”是在不同的项目中定义的,我只是意识到它们针对不同版本的.Net。看到我的回答 – wlyles