MVC4:程序集的清单定义与程序集引用不匹配

时间:2013-10-08 13:53:32

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

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

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

所有项目都使用NuGet配置了EntityFramework 5,所有项目都以.NET 4.5为目标。所有都设置为任何CPU。 64位Winddows 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" />

2 个答案:

答案 0 :(得分:0)

基于错误

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 framework 4.5上运行。

  1. 展开参考文献并检查EF版本。
  2. 检查升级日志中是否有任何错误和警告。

答案 1 :(得分:0)

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