New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-Database throwing "Could not load file or assembly EntityFramework .. or one of its dependencies" error #2592

Closed
ahmad-luqman opened this Issue Jul 24, 2015 · 16 comments

Comments

Projects
None yet
6 participants
@ahmad-luqman

ahmad-luqman commented Jul 24, 2015

I am trying to run the steps from https://github.com/NuGet/NuGetGallery/blob/master/README.md and when trying to run Update-Database call in Visual Studio 2013 Package Manager console getting the following errors:

PM> Update-Database -StartUpProjectName NuGetGallery -Debug -Verbose
Using StartUp project 'NuGetGallery'.
Using NuGet project 'NuGetGallery'.
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find
the file specified."
At C:\Stuffs\src\Github\NuGetGallery\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:5

  • $domain.CreateInstanceFrom(
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : FileNotFoundException

I am currently running Windows 8.1 and have Visual Studio 2012, 2013 and 2015 installed. I have searched it over the internet but similar error (but not same error as the following seems to be different:EntityFramework.psm1:431 char:5
) solutions seems to be not solving this problem.

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Jul 24, 2015

Contributor

Did you run package restore first? From that log it does look like it. Can you check all .config files for this? http://stackoverflow.com/questions/11749175/could-not-load-file-or-assembly-entityframework-after-downgrading-ef-5-0-0-0/11749176#11749176

Contributor

maartenba commented Jul 24, 2015

Did you run package restore first? From that log it does look like it. Can you check all .config files for this? http://stackoverflow.com/questions/11749175/could-not-load-file-or-assembly-entityframework-after-downgrading-ef-5-0-0-0/11749176#11749176

@ahmad-luqman

This comment has been minimized.

Show comment
Hide comment
@ahmad-luqman

ahmad-luqman Jul 25, 2015

No I haven't run the package restore. The log is different from the one mentioned in the stackoverflow link. I have also reproduced the same issue on a separate VM running on Azure with Windows 2012 RC + Visual Studio 2013. Not sure if its appropriate, but I can send that VM credentials to someone if they are interested to do any other diagnostics.

ahmad-luqman commented Jul 25, 2015

No I haven't run the package restore. The log is different from the one mentioned in the stackoverflow link. I have also reproduced the same issue on a separate VM running on Azure with Windows 2012 RC + Visual Studio 2013. Not sure if its appropriate, but I can send that VM credentials to someone if they are interested to do any other diagnostics.

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Jul 25, 2015

Contributor

Can you run package restore frst to make sure the assemblies are all downloaded and in place?

Contributor

maartenba commented Jul 25, 2015

Can you run package restore frst to make sure the assemblies are all downloaded and in place?

@ahmad-luqman

This comment has been minimized.

Show comment
Hide comment
@ahmad-luqman

ahmad-luqman Jul 26, 2015

I ran package restore but still same error.

ahmad-luqman commented Jul 26, 2015

I ran package restore but still same error.

@Antiohne

This comment has been minimized.

Show comment
Hide comment
@Antiohne

Antiohne Jul 26, 2015

I also have the same error message when I am trying to deploy the database with the Update-Database statement. I am using a Windows 8.1 machine with Visual Studio 2013.5 (Ultimate). At the moment I am researching this problem and what I know is that this problem is EF 5.0.0 - Code First Migrations related and maybe has something to do with the Visual Studio 2013 update 5 package I installed this week.

If I try the EF Code First Migration sample (https://msdn.microsoft.com/en-us/data/jj591621.aspx) with the EF 5.0.0 NuGet package I can create the initial database without problems. At the moment I use the Enable-Migrations command the same error message is raised which @ahmad-luqman reports. If I upgrade to EF 6.0.0 the Enable-Migrations command runs successfully.

With this knowledge I created a fresh VM with Visual Studio 2013.4. I created again the sample with EF 5.0.0 and the Enable-Migrations command give no errors. Upgrading the NuGet plugin from 2.8.5 to the latest version (2.8.6) has no influence on the EF 5.0.0 behavior. My next goal is upgrading this VM to VS 2013.5 level and I think the error will return at that moment. I will report the results when I am finished with this test.

Antiohne commented Jul 26, 2015

I also have the same error message when I am trying to deploy the database with the Update-Database statement. I am using a Windows 8.1 machine with Visual Studio 2013.5 (Ultimate). At the moment I am researching this problem and what I know is that this problem is EF 5.0.0 - Code First Migrations related and maybe has something to do with the Visual Studio 2013 update 5 package I installed this week.

If I try the EF Code First Migration sample (https://msdn.microsoft.com/en-us/data/jj591621.aspx) with the EF 5.0.0 NuGet package I can create the initial database without problems. At the moment I use the Enable-Migrations command the same error message is raised which @ahmad-luqman reports. If I upgrade to EF 6.0.0 the Enable-Migrations command runs successfully.

With this knowledge I created a fresh VM with Visual Studio 2013.4. I created again the sample with EF 5.0.0 and the Enable-Migrations command give no errors. Upgrading the NuGet plugin from 2.8.5 to the latest version (2.8.6) has no influence on the EF 5.0.0 behavior. My next goal is upgrading this VM to VS 2013.5 level and I think the error will return at that moment. I will report the results when I am finished with this test.

@Antiohne

This comment has been minimized.

Show comment
Hide comment
@Antiohne

Antiohne Jul 26, 2015

I just finished my upgrade test from VS 2013.4 to VS2013.5. After upgrading to VS2013 update 5 you will get errors with EF 5.0.0 Code First Migrations. Below you can see the error message I get when I tried to enable migrations for the sample. It is similar to the error reported by @ahmad-luqman.

PM> Enable-Migrations
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."
At C:\Projects\MigrationsDemo\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

I opened a bug item at Microsoft Connect (https://connect.microsoft.com/VisualStudio/feedback/details/1593363) for this VS 2013 update 5 behavior.

Antiohne commented Jul 26, 2015

I just finished my upgrade test from VS 2013.4 to VS2013.5. After upgrading to VS2013 update 5 you will get errors with EF 5.0.0 Code First Migrations. Below you can see the error message I get when I tried to enable migrations for the sample. It is similar to the error reported by @ahmad-luqman.

PM> Enable-Migrations
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."
At C:\Projects\MigrationsDemo\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

I opened a bug item at Microsoft Connect (https://connect.microsoft.com/VisualStudio/feedback/details/1593363) for this VS 2013 update 5 behavior.

@ahmad-luqman

This comment has been minimized.

Show comment
Hide comment
@ahmad-luqman

ahmad-luqman Jul 26, 2015

Yes. It worked once I downgraded VS2013 from Update 5 to Update 4.

ahmad-luqman commented Jul 26, 2015

Yes. It worked once I downgraded VS2013 from Update 5 to Update 4.

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Aug 3, 2015

Contributor

Not ideal, but you can use the following workaround:

  • Start Command Prompt as Administrator
  • Go to your packages directory and find the EntityFramework package directory.
  • Go to lib\net45
  • Type: gacutil /i EntityFramework.dll
  • Restart Visual Studio

We'll have to upgrade to the latest EF to support anything beyond VS2013.4.

Contributor

maartenba commented Aug 3, 2015

Not ideal, but you can use the following workaround:

  • Start Command Prompt as Administrator
  • Go to your packages directory and find the EntityFramework package directory.
  • Go to lib\net45
  • Type: gacutil /i EntityFramework.dll
  • Restart Visual Studio

We'll have to upgrade to the latest EF to support anything beyond VS2013.4.

@Antiohne

This comment has been minimized.

Show comment
Hide comment
@Antiohne

Antiohne Aug 3, 2015

Migration of EF 5 to EF 6.1.x version for the gallery code was one of the options I tried. You will get errors when building the project after the NuGet upgrade because there is a breaking change in EF 6. I tried to solve them but it took me to much time so I stopped with this scenario.

When I was updating the EF package I noticed that this solution uses a lot of old packages. More then 40 package updates where advertised and some of the updates are more than one year old.

Antiohne commented Aug 3, 2015

Migration of EF 5 to EF 6.1.x version for the gallery code was one of the options I tried. You will get errors when building the project after the NuGet upgrade because there is a breaking change in EF 6. I tried to solve them but it took me to much time so I stopped with this scenario.

When I was updating the EF package I noticed that this solution uses a lot of old packages. More then 40 package updates where advertised and some of the updates are more than one year old.

@adamskt

This comment has been minimized.

Show comment
Hide comment
@adamskt

adamskt Aug 28, 2015

I believe the issue is that "Entity Framework 6.1.3 Tools for Visual Studio 2015" tooling is telling VS2015 to look for the EntityFramework.dll at:
C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/EFTools/NuGet Packages/EntityFramework.5.0.0/lib/net45/EntityFramework.dll as evidenced by this assembly binding log:

*** Assembly Binder Log Entry  (8/28/2015 @ 10:17:23 AM) ***

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 14.0\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : NuGetGallery.Core, Version=3.9999.9999.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\Kelly\AppData\Local\Microsoft\VisualStudio\14.0\devenv.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: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/EFTools/NuGet Packages/EntityFramework.5.0.0/lib/net45/EntityFramework.dll.
LOG: All probing URLs attempted and failed.`

Looking in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\Microsoft.Data.Entity.Design.Package.pkgdef which presumably was dropped by the installation of the EF tools, I see this bit of telling config at the end:

// Enables the EntityDataSource connection wizard to work against Entity Framework 5 by registering a dependency
// assembly codebase in the registry to hint Visual Studio (or its express flavors) as to where to go look for
// the Entity Framework assembly when version 5 is required.
[$RootKey$\RuntimeConfiguration\dependentAssembly\codeBase\{29A768DC-8850-4C53-BC56-32D9E7925E00}]
"Name"="EntityFramework"
"PublicKeyToken"="b77a5c561934e089"
"Culture"="neutral"
"Version"="5.0.0.0"
"CodeBase"="$PackageFolder$\NuGet Packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll"

I ran the "Repair" option in Programs and Features on "Entity Framework 6.1.3 Tools for Visual Studio 2015", but the EF 5 bits still didn't show up in that location.

Solution

After creating a "NuGet Packages" folder under C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools and dropping the unpacked EntityFramework.5.0.0 bits in it from the packages folder in the NuGetGallery solution, Update-Database was able to complete without error.

Unfortunately, I have no idea where to file a bug or issue with the "Entity Framework 6.1.3 Tools for Visual Studio 2015" that ship with VS2015 RTM.

adamskt commented Aug 28, 2015

I believe the issue is that "Entity Framework 6.1.3 Tools for Visual Studio 2015" tooling is telling VS2015 to look for the EntityFramework.dll at:
C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/EFTools/NuGet Packages/EntityFramework.5.0.0/lib/net45/EntityFramework.dll as evidenced by this assembly binding log:

*** Assembly Binder Log Entry  (8/28/2015 @ 10:17:23 AM) ***

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 14.0\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : NuGetGallery.Core, Version=3.9999.9999.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\Kelly\AppData\Local\Microsoft\VisualStudio\14.0\devenv.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: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/EFTools/NuGet Packages/EntityFramework.5.0.0/lib/net45/EntityFramework.dll.
LOG: All probing URLs attempted and failed.`

Looking in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\Microsoft.Data.Entity.Design.Package.pkgdef which presumably was dropped by the installation of the EF tools, I see this bit of telling config at the end:

// Enables the EntityDataSource connection wizard to work against Entity Framework 5 by registering a dependency
// assembly codebase in the registry to hint Visual Studio (or its express flavors) as to where to go look for
// the Entity Framework assembly when version 5 is required.
[$RootKey$\RuntimeConfiguration\dependentAssembly\codeBase\{29A768DC-8850-4C53-BC56-32D9E7925E00}]
"Name"="EntityFramework"
"PublicKeyToken"="b77a5c561934e089"
"Culture"="neutral"
"Version"="5.0.0.0"
"CodeBase"="$PackageFolder$\NuGet Packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll"

I ran the "Repair" option in Programs and Features on "Entity Framework 6.1.3 Tools for Visual Studio 2015", but the EF 5 bits still didn't show up in that location.

Solution

After creating a "NuGet Packages" folder under C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools and dropping the unpacked EntityFramework.5.0.0 bits in it from the packages folder in the NuGetGallery solution, Update-Database was able to complete without error.

Unfortunately, I have no idea where to file a bug or issue with the "Entity Framework 6.1.3 Tools for Visual Studio 2015" that ship with VS2015 RTM.

@csalgo70

This comment has been minimized.

Show comment
Hide comment
@csalgo70

csalgo70 Sep 4, 2015

I am still running into this same issue. I have tried to build with both VS 2013 as well as VS2015. What files did you copy under C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools ?

csalgo70 commented Sep 4, 2015

I am still running into this same issue. I have tried to build with both VS 2013 as well as VS2015. What files did you copy under C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\EFTools ?

@adamskt

This comment has been minimized.

Show comment
Hide comment
@adamskt

adamskt Sep 4, 2015

adamskt commented Sep 4, 2015

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Sep 15, 2015

Contributor

We're fixing this going towards EF6 - keep an eye on #2669

Contributor

maartenba commented Sep 15, 2015

We're fixing this going towards EF6 - keep an eye on #2669

@maartenba

This comment has been minimized.

Show comment
Hide comment
@maartenba

maartenba Sep 29, 2015

Contributor

We're on EF6 now, GAC hack is no longer needed. Just a fresh clone / pull should do the trick.

Contributor

maartenba commented Sep 29, 2015

We're on EF6 now, GAC hack is no longer needed. Just a fresh clone / pull should do the trick.

@adamskt

This comment has been minimized.

Show comment
Hide comment
@adamskt

adamskt Sep 30, 2015

Excellent! :shipit:

adamskt commented Sep 30, 2015

Excellent! :shipit:

@ckieran

This comment has been minimized.

Show comment
Hide comment
@ckieran

ckieran May 5, 2016

Thanks to @adamskt your solution worked for me using VS2013 with update 5 installed on windows 10.
I Dropped the unpacked nuget package into that location (C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\ ... ) and everything started working again.
This was from an existing codebase that I pulled down from source control onto a freshly installed machine and then was unable to run the migrations on a newly created DB.

ckieran commented May 5, 2016

Thanks to @adamskt your solution worked for me using VS2013 with update 5 installed on windows 10.
I Dropped the unpacked nuget package into that location (C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\ ... ) and everything started working again.
This was from an existing codebase that I pulled down from source control onto a freshly installed machine and then was unable to run the migrations on a newly created DB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment