[英]TypeLoadException Method 'Set' does not have an implementation
I am using this InventoryMgmtContext
all over the place in my application and I haven't touched it for years. 我在应用程序中的所有地方都在使用这个
InventoryMgmtContext
多年来我都没有碰过它。 But I am now trying to use it in a new Test project and getting this issue. 但是我现在正尝试在新的Test项目中使用它并解决此问题。 The regular application still runs fine, the issue is just when trying to run this test.
常规应用程序仍然可以正常运行,问题出在尝试运行此测试时。 And all this passes compilation.
所有这些都通过编译。 The error is thrown at run time during test execution.
在测试执行期间,将在运行时引发该错误。
I did see this similar question , but none of the answers applied or worked for me. 我确实看到了类似的问题 ,但是没有一个答案适用于我。
Note all of these involved projects are all in the same solution. 注意所有这些涉及的项目都在同一个解决方案中。 Here are a few things I've tried.
这是我尝试过的几件事。
Not sure what else 不知道还有什么
Error: 错误:
Message: Test method ShopifyAdapterUnitTests.ManageProductTests.GetAndImportUpdatedProductsProducts threw exception: System.TypeLoadException: Method 'Set' in type 'OTIS.Domain.InventoryMgmt.InventoryMgmtContext' from assembly 'OTIS.Domain, Version=1.5.6983.16416, Culture=neutral, PublicKeyToken=null' does not have an implementation.
My IDbContext
interface: 我的
IDbContext
接口:
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace InciteCore.Domain
{
public interface IDbContext
{
DbSet<T> Set<T>() where T : class;
DbEntityEntry<T> Entry<T>(T entity) where T : class;
int SaveChanges();
void Dispose();
}
}
The partial class InventoryMgmtContext
created by Entity Framework DB First, which inherits from System.Data.Entity.DbContext
, which has a Set
method: 由Entity Framework DB First创建的部分类
InventoryMgmtContext
,它继承自System.Data.Entity.DbContext
,后者具有Set
方法:
namespace OTIS.Domain.InventoryMgmt
{
using System;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
public partial class InventoryMgmtContext : DbContext
{
public InventoryMgmtContext()
: base("name=InventoryMgmtContext")
{
}
<...>
}
}
I created my own partial class declaration to augment EFs to make sure it conforms to the IDbContext
interface, which specifies the Set
method. 我创建了自己的部分类声明以扩展EF,以确保它符合
IDbContext
接口,该接口指定Set
方法。 using InciteCore.Domain; 使用InciteCore.Domain; using System.Data.Entity;
使用System.Data.Entity;
namespace OTIS.Domain.InventoryMgmt
{
public partial class InventoryMgmtContext : DbContext, IDbContext
{
}
}
My test method, instantiating a new InventoryMgmtContext
, which is where the error is thrown. 我的测试方法是实例化一个新的
InventoryMgmtContext
,这是引发错误的地方。 Note I also include a call to it's Set
method!!! 请注意,我还包括对其
Set
方法的调用!!! So why could I be getting this error? 那为什么我会得到这个错误? This project does have a reference to both
OTIS.Domain.dll
and InciteCore.Domain
. 该项目确实同时引用了
OTIS.Domain.dll
和InciteCore.Domain
。
public async Task GetAndImportUpdatedProductsProducts()
{
InventoryMgmtContext dbContext = new InventoryMgmtContext();
var items = dbContext.Set<Item>(); <---- Set Method call!!!
var repository = new InciteCore.Data.Repository<StoreFront>(dbContext);
var storeFront = await repository.SearchFor(s => s.Id == 8).FirstOrDefaultAsync();
I faced same problem because I use IDbContext interface without implement this method DbSet<T> Set<T>() where T : class;
我遇到了同样的问题,因为我使用IDbContext接口而不实现此方法
DbSet<T> Set<T>() where T : class;
but the problem solved when I implement it in my Context base class in your case I think you need to Implement the IDbContext Methods in this partial class InventoryMgmtContext
但是在您的情况下,在我的Context基类中实现它时,问题解决了,我认为您需要在此局部类
InventoryMgmtContext
实现IDbContext方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.