我有一个奇怪的问题,我想如果有人可以告诉我为什么会发生这种情况.我在基本抽象类中有一个受保护的方法,如下所示:
protected T ForExistingEntity<T>(TEntity entity, object key, Func<Entity, T> action) {
entity = GetByKey(key);
if (entity != null)
return action(entity);
return default(T);
}
Run Code Online (Sandbox Code Playgroud)
我从继承类的原始调用如下:
return base.ForExistingEntity(
new MyEntity(), key, e => {
e.someFiled = 5;
return base.Update(e);
}
);
Run Code Online (Sandbox Code Playgroud)
执行此代码时,会在以下行中引发异常:
return action(entity);
Run Code Online (Sandbox Code Playgroud)
在基础抽象类中.例外是:
System.BadImageFormatException:尝试加载格式不正确的程序.(HRESULT异常:0x8007000B)
现在当我修改我的电话如下:
return base.ForExistingEntity(
new MyEntity(), key, e => {
e.someFiled = 5;
return Update(e);
}
);
Run Code Online (Sandbox Code Playgroud)
它运行正常,没有任何问题.
编辑:
Update方法位于基本抽象类中,如下所示:
public virtual bool Update(TEntity entity) {
Condition.Requires(entity, "entity")
.IsNotNull();
if (ValidateEntity(entity))
return Update(entity, true);
return false;
} …
Run Code Online (Sandbox Code Playgroud)