【问题标题】:MVC4: Assembly's manifest definition does not match the assembly referenceMVC4:程序集的清单定义与程序集引用不匹配
【发布时间】:2013-10-08 13:53:31
【问题描述】:

我是 MVC 的新手,所以请忍受一些迷失方向。我有一个包含以下项目的 .NET 4.5 解决方案:

  • Parkalot.Entity(包含实体类)
  • Parkalot.Database(包含数据上下文类)
  • Parkalot.Mvc4AspxClient(网络客户端)

所有项目都使用 NuGet 配置了 EntityFramework 5,并且所有项目都面向 .NET 4.5。全部设置为任何 CPU。 64 位 Windows 8 Pro 上的 Visual Studio 2013 Ultimate Preview(没关系)。

如果我尝试使用数据上下文从 Web 客户端的 Global.asax 访问数据库,它可以正常工作,因此直到 Web 客户端都没有问题。

添加控制器时,只要我选择[Empty MVC Controller]模板,就可以正常工作。当我尝试添加模板类型为 [MVC Controller with read/write actions and views, using Entity Framework] 的控制器并选择 Parkalot.Entity.Tenant 作为模型类并选择 Parkalot.Database.Context 作为数据上下文类时,出现以下错误:

Unable to retrieve metadata for 'Parkalot.Entity.Tenant'. Could not load file or assembly
'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or 
one of its dependencies. The located assembly's manifest definition does not match the 
assembly reference. (Exception from HRESULT: 0x80131040)

如果是相关的,我还会收到以下编译时警告:

C:\...\Microsoft.Common.CurrentVersion.targets(1613,5): warning MSB3247:
    Found conflicts between different versions of the same dependent assembly.
    Please add the following binding redirects to the "runtime" node in your
    application configuration file:

     - Parkalot.Mvc4AspxClient ->
        C:\...Parkalot.Mvc4AspxClient\bin\Parkalot.Mvc4AspxClient.dll

该解决方案最初是在 VS2010 中创建的,然后升级到 VS 2013 和 .NET 4.5。我想知道这是否是原因,但仍然不知道如何解决它。

编辑:如错误所示搜索4.4.0.0版本时,发现如下!

C:\...\Parkalot.WinFormsClient\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.WinFormsClient\Visual Studio\app.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
C:\...\Parkalot.Library\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Library\Visual Studio\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
C:\...\Parkalot.Entity\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Entity\Visual Studio\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
C:\...\Parkalot.Database\App.config(8):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Business\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Business\Visual Studio\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
C:\...\Parkalot.Configuration\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Test\App.config(5):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.WebFormsClient\Web.config(9):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
C:\...\Parkalot.Mvc4AspxClient\Web.config(9):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
C:\...\Parkalot.Mvc4RazorClient\Web.config(9):
 - <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

【问题讨论】:

    标签: c# .net asp.net-mvc-4 visual-studio-2012 entity-framework-5


    【解决方案1】:

    根据错误

    Unable to retrieve metadata for 'Parkalot.Entity.Tenant'. Could not load file or assembly
    'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or 
    one of its dependencies. The located assembly's manifest definition does not match the 
    assembly reference. (Exception from HRESULT: 0x80131040)
    

    此错误的可能原因可能是 EF 版本。而且你已经从VS2010升级了,看起来解决方案还在搜索上面的指定版本的程序集,但实际上VS2012使用了不同的版本。 EF5 在 .Net 框架 4.5 上运行。

    1. 扩展参考并检查 EF 版本。
    2. 检查升级日志是否有任何错误、警告。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,通过从 \bin 目录中删除文件解决了它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-06-10
        • 2018-10-13
        • 1970-01-01
        • 2011-08-20
        • 2016-09-21
        相关资源
        最近更新 更多