简体   繁体   English

TypeLoadException方法“设置”没有实现

[英]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. 这是我尝试过的几件事。

  • Cleaning and Rebuilding the project. 清理和重建项目。
  • Manually deleting files in the the bin folder of my Test project 手动删除测试项目的bin文件夹中的文件
  • Ensuring the referenced OTIS.Domain.dll version in the test project is the latest, that was created during the solution build. 确保测试项目中引用的OTIS.Domain.dll版本是最新的,该版本是在解决方案构建期间创建的。

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.dllInciteCore.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.

相关问题 System.TypeLoadException:方法“get_xxx”没有实现 - System.TypeLoadException: Method 'get_xxx' does not have an implementation TypeLoadException:类型中的方法“创建”...没有实现(以下错误) - TypeLoadException: Method 'Create' in type ... does not have an implementation (Error Below) Castle Keeps给我一个System.TypeLoadException:方法&#39;myMethod&#39;没有实现? - Castle Keeps giving me a System.TypeLoadException: Method 'myMethod' does not have implementation? 程序集“ myAssembly”中类型为“ MyNamespace.MyType”的System.TypeLoadException方法“ GetX”没有实现 - System.TypeLoadException Method 'GetX' in type 'MyNamespace.MyType' from assembly 'myAssembly' does not have an implementation 为什么会收到虚假的TypeLoadException“方法 <foo> 在类型上 <bar> 从组装 <baz> 没有实现”? - Why do I get a spurious TypeLoadException “Method <foo> in type <bar> from assembly <baz> does not have an implementation”? 方法“CommonCreateArrayTypeSymbol”没有实现 - Method 'CommonCreateArrayTypeSymbol' does not have an implementation System.TypeLoadException:get_TargetFramework没有实现 - System.TypeLoadException: get_TargetFramework doesn't have an implementation FakeItEasy异常方法没有实现 - FakeItEasy exception method does not have an implementation 方法在Servicestack Redis中没有实现 - Method does not have implementation in servicestack redis EF Core:方法“ProcessModelFinalized”没有实现 - EF Core: Method 'ProcessModelFinalized' does not have implementation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM