Enable Migrations Error

0

When trying to use Code First Migrations, the following error is occurring. Any ideas?

PM> enable-migrations
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\User1\Documents\Visual Studio 2013\
WebSites\Website1\C#\packages\EntityFramework.6.1.1\tools\Entity
Framework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\User1\Documents\Visual Studio 2013\WebSites\Website1\C#\
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 C:\Users\User1\Documents\Visual Studio 2013\WebSites\Website1\C#\
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:///C:\Users\User1\Documents\Visual St
udio 2013\WebSites\Website1\C#\packages\EntityFramework.6.1.1\to
ols\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\User1\Documents\Visual Studio 2013\WebSites\Website1\C#\
packages\EntityFramework.6.1.1\tools\EntityFramework.psm1:809 char:31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

PM> 
asp.net
asked on Stack Overflow Nov 12, 2015 by Mike • edited Nov 12, 2015 by Tgsmith61591

2 Answers

0

This has happened to me before, uninstalling and reinstalling Entity framework solved the issue.

Another time I had to reinstall and then close and re-open visual studio in order for it to work.

answered on Stack Overflow Nov 12, 2015 by UnitStack
0

This issue will occur if you dont have entity framework installed. Follow the below steps

Step1: Install the entity framework by going in to tools > NugetPackage manager > package manager console

Install-Package EntityFramework -IncludePrerelease

Step2: create a new class anywhere- later we can remove it

  public class MyDbContext : DbContext
    {
        public MyDbContext()
        {

        }
    }

Note: After DbContext use Shortcut {Alt / ctrl }. {ENTER} to ad Using Statement (using System.Data.Entity)

If we don't do this we will get another error:

No context type was found in the assembly

Then run the following command

enable-migrations

It should work.

answered on Stack Overflow Oct 30, 2018 by Ragavan Rajan

User contributions licensed under CC BY-SA 3.0