I am learning about ASP.NET MVC5 with Entity Framework. For my learning I'm using Lynda Video tutorials and I am stuck at the Nuget Console where I have to run the following code:
Enable-Migrations -ContextType ApplicationDbContext
After i run it I got the folowin error:
Enable-Migrations -ContextType ApplicationDbContext Exception calling
"LoadFrom" with "1" argument(s): "Could not load file or assembly
'file:///C:...\Projects\Lynda MVC - Exercise Files\Ch3 -
continue\Start\packages\EntityFramework.6.1.1\tools\EntityFramework.PowerShell.Utility.dll'
or one of its dependencies. Operation is not supported. (Exception
from HRESULT: 0x80131515)" At C:...\Projects\Lynda MVC - Exercise Files\Ch3 -
continue\Start\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:780
char:5
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path $ToolsP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException You cannot call a method on a null-valued expression. At
C:...\Projects\Lynda
MVC - Exercise Files\Ch3 -
continue\Start\packages\EntityFramework.6.1.1\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:///C:...\Projects\Lynda MVC - Exercise Files\Ch3
- continue\Start\packages\EntityFramework.6.1.1\tools\EntityFramework.PowerShell.dll'
or one of its dependencies. Operation is not supported. (Exception
from HRESULT: 0x80131515)" At C:...\Projects\Lynda MVC - Exercise Files\Ch3 -
continue\Start\packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:809
char:5
+ $domain.CreateInstanceFrom(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
If you can help me with any solution it will be a big help.
Use '-ContextTypeNameswitch instead, and specify yourDBContext` class. i.e,
Enable-Migrations -ContextTypeName Someproject.DepartmentDb
For more useful switches, refer THIS
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 to call to the problematical extension (EntityFramework.Powershell.utility.dll).
Related
I am trying to use the Xamrin forms map inteface to add custom pins acording to the doumenation here on microsoft but I am having an error it said that it should add the google play services automatically but it does not so I am trying to use the nuget.
Microsoft documentaiton
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/map
Nuget for google play sevices
https://www.nuget.org/packages/Xamarin.GooglePlayServices.Maps/
But I also get the following error.
GET https://nuget.telerik.com/nuget/FindPackagesById()?id='Xamarin.GooglePlayServices.Maps'&semVerLevel=2.0.0
Install-Package : Failed to retrieve information about 'Xamarin.GooglePlayServices.Maps' from remote source
'https://nuget.telerik.com/nuget/FindPackagesById()?id='Xamarin.GooglePlayServices.Maps'&semVerLevel=2.0.0'.
An error occurred while sending the request.
Unable to connect to the remote server
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
At line:1 char:1
+ Install-Package Xamarin.GooglePlayServices.Maps -Version 71.1610.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Strange thing is this i have it set to nuget.org
I have this asp.net core project (targeting standard framework) which I used to work on with VS 2015. I'd recently migrated the project to VS2017 and everything was going just fine until I needed a change in the db and as I ran the add-migration command I got this exception:
Exception calling "SetData" with "2" argument(s):
+ $domain.SetData('project', $project)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
I've seen people making all sort of suggestions here on SO like running VS as admin or upgrading EF libraries. those solutions did not work for me.
Also there's only one project in the solution so the default project in package manager console can't be wrong.
I tried to run this command:
Enable-Migrations -ContextType ApplicationDbContext
And getting this exception:
Enable-Migrations : The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enable-Migrations -ContextType ApplicationDbContext
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I am using vs 2015 community edition. Restarting and run it as administrator could not solve the issue. And if I try to run this command to reinstall Entity Framework:
Install-Package EntityFramework -IncludePrerelease
Getting this exception as well:
Install-Package : An error occurred while retrieving package metadata for 'Newtonsoft.Json.10.0.3' from source 'C:\Path\packages'.
At line:1 char:1
+ Install-Package EntityFramework -IncludePrerelease
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Please, Give me any solution.
its case sensitive type
enable-migrations -contexttypename DBCONTEXT
you can also see the available options from
get-help EntityFramework
I'm following getting started with EF 7 for UWP apps official tutorial.
When I'm at Add-Migration MyFirstMigration, it throws following error:
PM> Add-Migration MyFirstMigration
Add-Migration : Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 'AppShellProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. An attempt was made to load a program with an incorrect format."
At line:1 char:1
+ Add-Migration MyFirstMigration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException
+ FullyQualifiedErrorId : BadImageFormatException,Add-Migration
Has anyone figured out any workaround?
Great job #Anil. :)
Actually, since this kind of issue may be related to Visual Studio tools or NuGet. By searching "CreateInstanceAndUnwrap Add-Migration" in EF repository on GitHub, you will see some issues there. If you cannot find any existing issues next time, as same as the questions(project.json, project type and etc. ) I asked, try to find out what's the difference between your steps/configurations and the tutorial will be helpful and you will have more info to get a quick answer.
I believe #bricelam has pointed out the issue you encountered, and no one is more familiar with EF7 than him. I want to pick some key messages from #bricelam in that issue as the ending:
Correct, the Migration commands won't work with x64 assemblies. The current implementation executes inside of an AppDomain created from VS (devenv.exe) which is a 32-bit process.
you'll have to use x86 at design-time.
I am trying to enable Code First in my Visual Studio Web Express 2012. From what I have read so far I have to use the Package Manager Console and the command Enable-Migrations. When I do this I get the following error.
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398 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 E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:399 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:///E:\Working\wingtoysdl\C#\packages\EntityF
ramework.5.0.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
As you can see it is a very large error making it very hard to google and troubleshoot. Does anyone have any ideas on how I can fix this?
I've run into this issue twice now. Both times I've had to uninstall entity framework then re-install it for each project in the solution. One thing that took me a while to figure out the second time I did this is that I had to re-start Visual Studio (2012) after re-installing Entity Framework (or I continued to get the "Could not load file or assembly '[path]\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll'" error).
To get to the Package Manager Console go to: Tools -> Library Package Manager -> Package Manager Console
In the Package Manager uninstall Entity Framework for each project (I selected each project from the Default Project dropdown at the top of the Package Manager Console):
Uninstall-Package EntityFramework -Force
Then install it for each project:
Install-Package EntityFramework
At this point attempting to run the Enable-Migrations command gave the error still, until I closed and restarted Visual Studio. Then it was successful, as was the Update-Database command (after setting AutomaticMigrationsEnabled to true in the Migrations.Configuration file).
Had the same issue on two different machines while using projects on a network drive. This answer fixed it for me.
This may be a late answer but this seems like it could be a permissions/access problem.
Make sure that your project is not being opened from a mapped drive or similar.
If you are on a corporate network and logged into a domain, it is very likely that your user profile does not actually sit on your local computer but rather on the server. This will cause the same problem.
Try copy the project to your local c: and try again.
My problem was caused by some projects in my solution not being updated to the same version as other projects. When I ensured all were on the same EF version, it began working.
So I had the same problem for a while, I was unpacking a working project and got the error as I tried to enable migrations. It was simply fixed by using 7-Zip instead of the default unzipper from windows 10
I was also encounter the same problem so I started to check the possible things could go wrong and I found 2 different versions of entity framework is get installed somehow.
To confirm I goto Tools> NuGet package manager solution > Manage NuGet packages > Consolidate.
Have a look below images.
In this picture you may clearly see the different version is installed
in this picture I am agree to update the Entity Framework from 6.2.0 to 6.4.4
I had the same issue and in my case it was network drive problem. When I copied my project in local drive it worked fine.