I'm new with EF and I have an error when I try to run Enable-Migrations in PMC console :
Exception calling "LoadFrom" with "1" argument(s):
"Could not load file or assembly 'file:///...\pa
ckages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:780 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:781 char:50
+ $dispatcher = $utilityAssembly.CreateInstance <<<< (
+ CategoryInfo : InvalidOperation: (CreateInstance:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///...\packages\EntityFramework.6.0.1\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is no t supported. (Exception from HRESULT: 0x80131515)"
At ...\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:809 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
I just ran into this on one of my co-worker's machine. The solution was:
Uninstall EF NuGet package
Manually remove Entity Framework sections from the Web.Config/App.Config files
Close Visual Studio
Re-open the solution in Visual Studio
Reinstall the EF NuGet Package
So openn the solution folder in file explorer, can you find the .dlls they are looking for in "Packages" folder then EntityFramework 6.0.1 folder? If not, there are two options:
Check your source control server, there is a possibility it was not downloaded to local workspace. if so, just get them manually from source control explorer if you are using TFS.
If the files were not on source control server either, I would recommend to uninstall EF 6.0.1 nuget, then manual delete the whole folder about ef in the Package folder above, and then reinstall it.
I had the same problem. My project was stored in a network drive. There are many security policies applied to my PC. I moved my project to the local hard drive, and the problem was solved.
It seems like "EntityFramework.Powershell.utility.dll" is tring to use some powershell functionality, and the system is preventing to execute such calls, maybe because the dll that is calling powershell is not a local file.
In your case, make sure that you do not have any security policy or system configuration that would prevent your system execute the problematical extension from a non local drive (EntityFramework.Powershell.utility.dll)
Faced similar problem. Reason of the problem was shifting of my code from one machine to another...Removing and then reinstalling entity framework solved the problem.
Update the Entity Package from Package Manager Console or browser.
Related
I am using visual studio 2019 Ent and EntityFramework.6.4.4.
Whenever I'm restarting my VS19 and going to access EF it gives me the following error with code first approach.
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///("Project Name")\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. The
system cannot find the file specified."
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:782 char:5
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
You cannot call a method on a null-valued expression.
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:783 char:5
+ $dispatcher = $utilityAssembly.CreateInstance(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///"(Project Name)"\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.dll' or one of its dependencies. The system
cannot find the file specified."
At "(Project Name)"\packages\EntityFramework.6.2.0\tools\EntityFramework.psm1:811 char:5
+ $domain.CreateInstanceFrom(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileNotFoundException
What I have tried so far:
I found one temporary solution that by reinstalling every time nugete package i.e entity framework and it works.
But this is annoying and definitely not the solution. Looking for a permanent solution.
Thanks in advance.
In my case I was executing the
Add-Migration
command. Instead, I used
EntityFramework6\Add-Migration
And I had no more errors. (Thanks to this answer I found https://stackoverflow.com/a/58951090/2546759)
Another thing which did the trick was:
Make sure that all projects in the solution are using same EF version.
Restart Visual Studio.
(As suggested here: https://stackoverflow.com/a/70004476/2546759)
I was working on ASP.Net boilerplate framework and now that machine is not available where i was working, But i have backup on my Google drive. How i can use that backup properly? Database creation , project running etc???
I am getting error on Enable-Migrations and Update Database Commands
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///F:\Qubit
Systems\ShipperBuyerV1\module-zero-template-2.1.1\src\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported.
(Exception from HRESULT: 0x80131515)"
At F:\Qubit Systems\ShipperBuyerV1\module-zero-template-2.1.1\src\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:5
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
You cannot call a method on a null-valued expression.
At F:\Qubit Systems\ShipperBuyerV1\module-zero-template-2.1.1\src\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:5
+ $dispatcher = $utilityAssembly.CreateInstance(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///F:\Qubit
Systems\ShipperBuyerV1\module-zero-template-2.1.1\src\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception
from HRESULT: 0x80131515)"
At F:\Qubit Systems\ShipperBuyerV1\module-zero-template-2.1.1\src\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 char:5
+ $domain.CreateInstanceFrom(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
Here is what you should do:
Download the project from your Google drive
Open in Visual Studio
Run Database-Update (Make sure the Entity Framework project is selected in the Nuget Package Manager.
That is all you need to do to get. All you will lose is the data in your previous database on the unavailable machine.
Best solution is to create a repo in Git, add you project in it. On there PC run git clone on the desired path.
Refer Setting up git repo
I have a class library project that has a DbContext class in it that looks like this:
public DbContext() : base(ContextInitializer.GetConnectionStringName())
{
So that the user (other programmers) can set this on their application startup when they can use my API and entities on whatever database they choose in whatever project and set the connection string then. Now I am trying to generate a migration configuration in my class library. I've tried:
Enable-Migrations -ProjectName "ClassLibraryProject" -ContextTypeName "MyDbContext" -StartUpProjectName "MyWebApp" -ConnectionString "MyConnectionString" -ConnectionProviderName "System.Data.SqlClient"
Based on other answers on here who encounter the same error, and it doesn't help. I still get:
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable."
At C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+ $domain.SetData('project', $project)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
Exception calling "SetData" with "2" argument(s): "Type
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'
in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,
Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is
not marked as serializable." At
C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719
char:5
+ $domain.SetData('contextProject', $contextProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
Exception calling "SetData" with "2" argument(s): "Type
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'
in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,
Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is
not marked as serializable." At
C:\Users\me.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:720
char:5
+ $domain.SetData('startUpProject', $startUpProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
Other answers I've seen on here say use -StartUpProjectName param, and I did that but still get the error. I thought it was because my projects were in nested folders in the solution I am working in, but supplying the project names as "path/ProjectName" triggered an error that project wasn't found, so that can't be it.
EDIT: I found this: EF 6 with a dnx project, my project is Asp.NET Core class library targeting 461 runtime and being used in Asp.NET Core Web app. So there is no way to run a migration in a class library using EF 6 with ASP.NET Core?
Okay, so after much looking, you can't do this by default. No tooling for class libraries since January at all, which seems horrible to me. And no tooling as the link I posted mentions for a .NET CORE class library targeted at 461 using EF6, because EF6 tools do not recognize project.json dependency format.
However, blessed be, a gentleman by the name of Mohammad Rahhal created such a library to accomplish this: https://github.com/mrahhal/Migrator.EF6/blob/master/README.md
And using the information described in this issue: https://github.com/mrahhal/Migrator.EF6/issues/9
I was able to successfully run a migration, it does require some hacky stuff, but it works for the time being, better than other alternatives provided elsewhere.
1) Download this nuget package for Migrator.EF6.Tools nuget.
2) Change project.json to include:
{
"version": "1.0.0-*",
"dependencies": {
"EntityFramework": "6.1.3",
"Migrator.EF6.Tools": "1.0.5"
},
"frameworks": {
"net461": {}
},
"buildOptions": {
"emitEntryPoint": true
},
"tools": {
"Migrator.EF6.Tools": {
"imports": "portable-net45+win8+dnxcore50",
"version": "1.0.5"
}
}
}
3) Add a program.cs file with Main stub to the class library project:
public class Program
{
public static void Main(string[] args)
{
}
}
You are now set to run migrations from VS2015 Dev Command Prompt. Navigate to the project directory, and run the migration commands described in the readme linked above.
However, it should be noted, once you are done running migrations, set emitEntryPoint value to false again so it can still be treated like a normal class library. Basically you are tricking the EF tooling to think your class library is a console app, but you don't want it to be treated like that for deployment.
Ensure MyWebApp has a web.config with a connection string named MyConnectionString.
Enable-Migrations
-ProjectName "ClassLibraryProject"
-ContextTypeName "MyDbContext"
-StartUpProjectName "MyWebApp"
-ConnectionString "MyConnectionString"
-ConnectionProviderName "System.Data.SqlClient"
I m Using Visual Studio 2017
where I was able to successfully run a migration,, it does require
Installation of following NuGet Packages in your class library where DbContext located
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
I had the same problem this morning and I updated the EF nuget package to Entity Framework 6.3.0. That helped.
I'm new to using MVC, and when working through the tutorials regarding migrations in Visual Studio 2013 I appear to have broken the tie-in to EntityFramework in the Package Manager console.
I believe this started when I updated the EntityFramework to version 6.1.3, But that appears to be incompatible with the MVC Controller scaffolding. So I rolled it back to version 5.0.0.
When I now enter the command enable-migrations
I get the following error:
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 D:\ss\CAP\CAP_MVC_Dev_2\CAP_MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodTargetInvocation
The file EntityFramework.psm1 exists where it is described above, but the error appears to be in that file? How is $domain.CreateInstanceFrom missing, and where from? Uninstalling and reinstalling the EntityFramework package makes no difference.
I've tried creating new projects from scratch and this error persists across them. An uninstall/reinstall of Visual Studio 2013 has not resolved the issue either, nor has destroying the connected database and starting again with an empty one.
So, it turns out the solution was similar to this one
Entity Framework code first migrations throwing error
When I first attempted this solution there were reports of gacutil not being recognised. Due to the environment I work it it is not simple to add the gacutil to be universally recognised (I believe), so i found the gacutil.exe in the file system, copied that to the lib\net45 folder referenced in the linked post, and then ran the command
gacutil /i EntityFramework.dll
This has resolved the problem, and i no longer receive the 'File not Found error'
Instead of installing with GAC, I came to the following solution (VS2013 SP5 + EF 5):
Copied (Solution dir)\packages\EntityFramework.5.0.0 (entire directory)
to
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\NuGet Packages\
The NuGet Packages directory did not exist, so one needs to create it manually.
When I try to install Web Grease 1.5.1 I get this error:
You cannot call a method on a null-valued expression.
At L:\PROJECT_PATH\packages\WebGrease.1.5.2\tools\install.ps1:45 char:5
+ $msbuild.Xml.AddProperty("WebGreaseLibPath", $relativePackageUri.ToString(). ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Delete all the folders inside the "packages" folder in your application folder. Then try to reinstall web grease from nuget. See if that solves your issue.