【发布时间】:2014-07-22 19:59:57
【问题描述】:
我的代码中出现 System.TypeLoadException,描述如下:
Could not load type 'System.Func`2' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
这基本上是我在错误附近所做的事情,没有 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();
这是 Base 的基础知识:
public abstract class Base : SomeOtherClass
{
protected Base() : base() {}
public void Foo()
{
// do stuff
}
}
以下是 Derived 的基础知识:
public class Derived : Base
{
// overrides SomeOtherClass.Foo(), which is the only abstract method
protected override void Foo()
{
// do stuff
}
}
【问题讨论】:
-
你的环境是什么?这是桌面应用程序吗? Windows 商店/运行时应用程序?网络应用程序?您的应用针对的是哪个版本的 .net 框架?
-
Bar()定义在哪里? -
你们走在正确的轨道上。
Derived和Base是在不同的项目中定义的,我刚刚意识到它们针对不同版本的 .Net。看我的回答
标签: c#