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?
For those developers, Entity Framework has a modeling workflow referred to as Code First. Code First modeling workflow targets a database that doesn't exist and Code First will create it. It can also be used if you have an empty database and then Code First will add new tables to it.
To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add. This will open the Entity Data Model wizard as shown below.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With