C# 实体框架 5 - 无法加载文件或程序集 EntityFramework,版本 = 5.0.0.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11471347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:59:00  来源:igfitidea点击:

Entity Framework 5 - Could not load file or assembly EntityFramework, Version=5.0.0.0

c#entity-frameworkentity-framework-ctp5

提问by Kobojunkie

I am trying to use Entity Framework 5 for my project but I seem to be having some issue getting the assembly installed to comply. And since I installed this initially using nuget, I am not certain what I need to do to cause this to work as I expect . Any help on what I need to do to fix this problem please?

我正在尝试将 Entity Framework 5 用于我的项目,但我似乎在安装程序集以符合要求时遇到了一些问题。由于我最初使用 nuget 安装了它,因此我不确定我需要做什么才能使其按预期工作。请问我需要做些什么来解决这个问题?

*System.IO.FileNotFoundException : Could not load file or assembly EntityFramework, Version=5.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089' or one of it's dependencies The System cannot find the file specified.WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registy value . . . *

* System.IO.FileNotFoundException:无法加载文件或程序集 EntityFramework,版本=5.0.0.0,Culture=Neutral,PublicKeyToken=b77a5c561934e089' 或其依赖项之一系统找不到指定的文件。警告:程序集绑定日志已关闭. 要启用程序集绑定失败日志记录,请设置注册表值。. . *

by using fusion log, i got this

通过使用融合日志,我得到了这个

*** Assembly Binder Log Entry  (7/17/2012 @ 9:29:09 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = WORKALOT\Tokorie
LOG: DisplayName = Budget.Data, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Development/Summer2012BudgetApp/Budget.Service.Test/bin/Release
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = vstest.executionengine.x86.exe
Calling assembly : Budget.Lib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Development/Summer2012BudgetApp/Budget.Service.Test/bin/Release/Budget.Data.DLL.
LOG: Attempting download of new URL file:///C:/Development/Summer2012BudgetApp/Budget.Service.Test/bin/Release/Budget.Data/Budget.Data.DLL.
LOG: Attempting download of new URL file:///C:/Development/Summer2012BudgetApp/Budget.Service.Test/bin/Release/Budget.Data.EXE.
LOG: Attempting download of new URL file:///C:/Development/Summer2012BudgetApp/Budget.Service.Test/bin/Release/Budget.Data/Budget.Data.EXE.
LOG: All probing URLs attempted and failed.

回答by Tommy Grovnes

Run the fusion log toolas suggested by the error message to get more information about where the runtime is looking for the dll's so you get a better idea of why it is failing.

按照错误消息的建议运行融合日志工具,以获取有关运行时在何处查找 dll 的更多信息,以便您更好地了解它失败的原因。

There is a good article about Fusion-loggningby Scott Hanselman, how you enable it etc, then just run fuslogw as admin from command prompt.

Scott Hanselman有一篇关于Fusion-loggning的好文章,如何启用它等,然后只需从命令提示符以管理员身份运行 fuslogw。

Update

更新

The fusion log shows us where the runtime is looking for your DLLs, in this case Budget.Data, which it looks for in:

融合日志向我们展示了运行时在何处查找您的 DLL,在本例中为 Budget.Data,它在以下位置查找:

bin/Release/Budget.Data.DLL 
bin/Release/Budget.Data/Budget.Data.DLL
bin/Release/Budget.Data.EXE
bin/Release/Budget.Data/Budget.Data.EXE

Can you verify that the DLL is in fact in one of these directories ? If it is check the target framework on your DLL (check the project properties) ? Is the target framework compatible with EF 5.0 ? What is the target framework of your other assemblies (if any)

您能否验证 DLL 实际上位于这些目录之一中?如果是检查 DLL 上的目标框架(检查项目属性)?目标框架是否与 EF 5.0 兼容?你的其他程序集的目标框架是什么(如果有的话)

回答by gabba

  1. Check the flag "copy local"
  2. Check the assembly dll exists in out put folder
  3. Check reference in solution. Try readd reference.
  4. Check the version and public key of assembly and in solution file (You can open the visual studio solution file and edit it in text editor. Try remove public key from solution file and set correct version if its difers)
  5. Also this problem can hapen when some assembly you add to solution references to assembly that you did't have. If that try to get correct assembly or try rebuild assembly with libraries you have.
  1. 检查标志“复制本地”
  2. 检查输出文件夹中是否存在程序集dll
  3. 检查解决方案中的参考。尝试阅读参考。
  4. 检查程序集和解决方案文件中的版本和公钥(您可以打开visual studio解决方案文件并在文本编辑器中进行编辑。尝试从解决方案文件中删除公钥并设置正确的版本,如果其不同)
  5. 当您将某些程序集添加到您没有的程序集的解决方案引用时,也会发生此问题。如果尝试获得正确的程序集或尝试使用您拥有的库重建程序集。

Good luck!

祝你好运!

回答by Shahin Dohan

Are you sure the path is correct? Try to remove the "Entity Framework" reference and re-adding it manually.

你确定路径正确吗?尝试删除“实体框架”引用并手动重新添加。

Right click to add a reference, then browse here and add the dll:

右键单击添加引用,然后浏览此处并添加 dll:

C:\PATH\TO\SOLUTION\packages\EntityFramework.5.0.0-rc\lib\net45\EntityFramework.dll

C:\PATH\TO\SOLUTION\packages\EntityFramework.5.0.0-rc\lib\net45\EntityFramework.dll

Also make sure the path is set in the csproj file of the project (right click project, unload, right click again and then "Edit projectname.csproj"), you should have something like this:

还要确保在项目的 csproj 文件中设置了路径(右键单击项目,卸载,再次右键单击然后“编辑 projectname.csproj”),您应该有这样的内容:

<Reference Include="EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.5.0.0-rc\lib\net45\EntityFramework.dll</HintPath>
</Reference>

Other things to check would be the packages.config file to make sure it's referenced there, and also make sure that the Entity Framework reference's "Copy Local" property is set to true. You might also have to reference the assembly in your web.config file if you're using it in an ASP.NET projcet or something similar.

其他要检查的事情是packages.config 文件,以确保在那里引用它,并确保实体框架引用的“Copy Local”属性设置为true。如果你在 ASP.NET 项目或类似的东西中使用它,你可能还需要在你的 web.config 文件中引用它。

回答by Wulfram

What blocks are you using from EntLib5? Since you are calling it from the DAL, I will assume you are calling Microsoft.Practice.EnterpriseLibrary.Data.

您使用 EntLib5 中的哪些块?由于您是从 DAL 调用它,因此我假设您正在调用 Microsoft.Practice.EnterpriseLibrary.Data。

If so, I just want to point out that I always needed all of the following DLLs to get the EntLib5 DAAB to work for me.

如果是这样,我只想指出我总是需要以下所有 DLL 才能让 EntLib5 DAAB 为我工作。

Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.Unity
Microsoft.Practices.Unity.Interception

Missing any one of those references will cause my project to error out at runtime, even if compiles fine.

缺少这些引用中的任何一个都会导致我的项目在运行时出错,即使编译正常。

I would also try running the EntLib5 installer from http://www.microsoft.com/en-us/download/details.aspx?id=15104, since it sticks the DLLs into the GAC.

我还会尝试从http://www.microsoft.com/en-us/download/details.aspx?id=15104运行 EntLib5 安装程序,因为它将 DLL粘贴到 GAC 中。

回答by thomrand

I actually had this problem myself the other day, when working with version control (git) and the Nuget package for ef5-rc. What solved the issue for me was to remove (delete in Windows explorer) the assembly from the solutions' "packages" folder. When i restarted Visual Studio Nuget gave me the opportunity to restore packages. Hope this helps!

前几天,当我使用版本控制 (git) 和 ef5-rc 的 Nuget 包时,我自己实际上遇到了这个问题。对我来说解决问题的是从解决方案的“包”文件夹中删除(在 Windows 资源管理器中删除)程序集。当我重新启动 Visual Studio Nuget 时,我有机会恢复包。希望这可以帮助!

回答by BigDubb

I ended up solving this for a project I am working on. I ended up deleting everything in the .bin folder for the project that was throwing the error. I assume that these files only get re-written as specific times or when a .dll changes etc. and was not handled by the migration over. Deleting those files, cleaning the solution and rebuilding seemed to solve the problem for me.

我最终为我正在从事的项目解决了这个问题。我最终删除了抛出错误的项目的 .bin 文件夹中的所有内容。我假设这些文件只会在特定时间或 .dll 更改等时被重写,并且不会被迁移处理。删除这些文件,清理解决方案并重建似乎解决了我的问题。

回答by TheMagnificent11

I'm getting this problem too. So I did a bit of a look around and found the following.

我也遇到这个问题 所以我环顾四周,发现了以下内容。

In the "Common Problems" section of http://msdn.microsoft.com/en-us/data/jj618307.aspxit says...

http://msdn.microsoft.com/en-us/data/jj618307.aspx的“常见问题”部分中,它说...

"This typically means that you are running a .NET 4 application without the Redirect.config file. You need to copy the Redirect.config to the same location as migrate.exe and rename it to migrate.exe.config."

“这通常意味着您正在运行没有 Redirect.config 文件的 .NET 4 应用程序。您需要将 Redirect.config 复制到与 migrate.exe 相同的位置,并将其重命名为 migrate.exe.config。”

Unfortunately, I don't know where Redirect.configis located. The cannot find it anywhere in the NuGet package's directory contents.

不幸的是,我不知道Redirect.config位于何处。在 NuGet 包的目录内容中找不到它。