Search code examples
asp.netasp.net-mvcentity-frameworkasp.net-mvc-4nuget

ASP.NET MVC Nuget Enabling-Migrations


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.


Solution

  • Use '-ContextTypeNameswitch instead, and specify yourDBContext` class. i.e,

    Enable-Migrations -ContextTypeName Someproject.DepartmentDb
    

    For more useful switches, refer THIS