I am using this InventoryMgmtContext
all over the place in my application and I haven't touched it for years. But I am now trying to use it in a new Test project and getting this issue. 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.
- Cleaning and Rebuilding the project.
- Manually deleting files in the the bin folder of my Test project
- Ensuring the referenced OTIS.Domain.dll version in the test project is the latest, that was created during the solution build.
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:
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:
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.
using InciteCore.Domain;
using 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. Note I also include a call to it's Set
method!!! So why could I be getting this error? This project does have a reference to both OTIS.Domain.dll
and 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();