无法加载文件或程序集“EntityFramework”或其依赖项之一

时间:2012-10-06 14:11:04

标签: asp.net-mvc-3

我的ASP.NET MVC3 Web应用程序运行正常。但当我重新启动我的电脑,然后尝试更新MS VS 2010中的应用程序时,它在运行应用程序期间显示错误:

Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

说明

An unhandled exception occurred during the execution of the current web request. Please 
review the stack trace for more information about the error and where it originated in the code. 

异常详细信息: System.IO.FileLoadException:无法加载文件或程序集“EntityFramework”或其依赖项之一。参数不正确。 (HRESULT异常:0x80070057(E_INVALIDARG))

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

程序集加载跟踪:以下信息有助于确定无法加载程序集“EntityFramework”的原因。

警告:装配绑定日志记录已关闭。 要启用程序集绑定失败日志记录,请将注册表值[HKLM \ Software \ Microsoft \ Fusion!EnableLog](DWORD)设置为1。 注意:程序集绑定失败日志记录会导致一些性能损失。 要关闭此功能,请删除注册表值[HKLM \ Software \ Microsoft \ Fusion!EnableLog]。

堆栈追踪:

[FileLoadException: Could not load file or assembly 'EntityFramework' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]

[FileLoadException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591

[HttpException (0x80004005): Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

然后我清除所有Windows临时文件和ASP.NET临时文件,然后再次运行该应用程序。但情况没有改善。你能帮我解决一下吗。谢谢。

5 个答案:

答案 0 :(得分:14)

只需重新添加实体框架工具库包管理器 - >包管理器控制台

类型:

Install-Package EntityFramework

它将恢复(您正在运行v 4.4,这是Visual Studio 2010中的v5版本)

如果您想要“干净”,可以先尝试卸载。即使失败也没有任何伤害。

Uninstall-Package EntityFramework

答案 1 :(得分:13)

如果其他答案都不适合您(包括关于同一问题的其他类似问题的答案),请尝试以下适用于我的方法(根据http://forums.devart.com/viewtopic.php?f=3&t=26327):

在应用程序的* .config文件中添加以下XML以解决问题:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
      <bindingRedirect oldVersion="4.4.0.0" newVersion="5.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>
  </runtime>

答案 2 :(得分:8)

确保所有项目都针对同一个.NET Framework。我有一个.NET 4.5项目,引用了一个使用4.0的类库,我遇到了这个问题,一旦我将其更改为4.5,它工作正常,我可以使用NuGet包管理器控制台安装EF

答案 3 :(得分:3)

我收到了这个错误。事实证明比其他一些答案更简单:我有两个项目引用了不同版本的Entity Framework。一个来自包含最新版本的NuGet包,另一个来自ASP.NET MVC 4模板。

我的修复是从MVC 4项目中删除对旧版EF(5)的引用,并使用NuGet安装最新版本。之后一切都很好。

答案 4 :(得分:2)

我遇到了类似的问题,我不得不手动删除解决方案中的包文件夹以及packages.config文件中对包的引用,然后使用包管理器控制台重新安装它来修复它。