Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 893
Kobojunkie Avatar asked Jul 13 '12 13:07

Kobojunkie


4 Answers

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)

like image 136
Tommy Grovnes Avatar answered Nov 19 '22 00:11

Tommy Grovnes


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.

like image 43
Shahin Dohan Avatar answered Nov 19 '22 01:11

Shahin Dohan


  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!

like image 1
gabba Avatar answered Nov 19 '22 01:11

gabba


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!

like image 1
thomrand Avatar answered Nov 19 '22 01:11

thomrand