Entity Framework 5 - Could not load file or assemb

2019-06-15 01:53发布

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?

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

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.

7条回答
冷血范
2楼-- · 2019-06-15 02:35

Run the fusion log tool as 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.

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

Update

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

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)

查看更多
一夜七次
3楼-- · 2019-06-15 02:40

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.aspx it says...

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

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

查看更多
戒情不戒烟
4楼-- · 2019-06-15 02:42
  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.

Good luck!

查看更多
时光不老,我们不散
5楼-- · 2019-06-15 02:43

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:

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:

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

查看更多
叼着烟拽天下
6楼-- · 2019-06-15 02:45

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.

查看更多
手持菜刀,她持情操
7楼-- · 2019-06-15 02:51

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.

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.

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.

查看更多
登录 后发表回答