I have installed Entity Framework thorough nuget. I have VS2019 .net console application.
In the Package Manager console, I run Enable-Migrations.
I get exception:
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:18
+ Enable-Migrations <<<<
+ CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I am currently using Visual Studio 2019 and this worked for me.
You need to install first Entity Framework
Install-Package EntityFramework -IncludePrerelease
Then try to make sure that one of your classes inherits data context
Try running enable-migrations again.
Related
I can add a migration from the console using dnx like so:
dnx . ef migration add test
But I can't do it via Visual Studio's Package Manager Console, using the same line above. The error I get is:
dnx : System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
At line:1 char:1
+ dnx . ef migration add test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System.InvalidO...ersion=v4.5.1'::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
EntityFramework.Commands 7.0.0-beta5
EntityFramework.SqlServer 7.0.0-beta5
...
Is the PMC running for 4.5.1 and the console something else?
I would prefer to run the dnx commands from the Package Manager rather than a separate window, as we used to using Add-Migration...
The Package Manager Console wasn't in the right directory. I needed to cd src\appname to get into the right folder before running the dnx command.
I have several class files. Now I am adding a new model class and tried to type add-migration InitialCreate but am getting the following error:
PM> add-migration InitialCreate
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\user\Documents\Visual Studio 2013\Pro
jects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operati
on is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 c
har: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\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 c
har: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\user\Documents\Visual Studi
o 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Opera
tion is not supported. (Exception from HRESULT: 0x80131515)"
At C:\Users\user\Documents\Visual Studio 2013\Projects\DigitalHealthWebPrev\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:809 c
har:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
PM>
Using the Package Manager, you need to re-install Entity Framework:
Uninstall-Package EntityFramework -Force
Then install it for each project:
Install-Package EntityFramework
Then do not forget to restart the studio.
https://stackoverflow.com/a/14994432/1845408
Used the command EntityFramework6\add-migration {migration name} instead. Microsoft changed the name of the command.
Just restart the visual studio and clean the solution and rebuild it again.
Make sure that VS in admin mode
In my case, it was a different entity-framework version between main project and the project containing DbContext.
I just updated version of package in both projects to v6.4.4
I had a slightly different case today, I'm wirting the details here in case that might help somebody. The error was referencing one of my assemblies instead, on which the assembly containing the EF DbContext was depending.
I solved it setting the referenced assembly to "Copy Local" "true" so it'd make a local copy when building for migrations and therefore be able to find it.
you need to re-install Entity Framework:
I went to "Manage Nuget Packages for Solution..." and updated all my packages. This worked for me.
Then I got another error Cannot bind argument to parameter 'Path' because it is null.
Setting another project as startup project other then my web app, before running any EF command in Package Manager Console, worked for me.
Whats missing are the dlls from (Solution Folder)/packages/EntityFramework.6.1.3/tools/.
Things I would try:
Nuget will keep a copy of the .nupkg you might find the missing files there ((Solution Folder)/packages/EntityFramework.X.Y.Z/) (Open the nupkg as zip)
If not you may have luck redownloading the package manually here https://www.nuget.org/packages/EntityFramework (Make sure you download the right packages. In your case it would be 6.1.3)
If that doesnt work you can retry one of the above solutions of completely removing and reinstalling EF but make sure you install the same version for each project.
Also there seem to be versions that dont include those files. For example as of writing this answer 6.3.0 actually doesnt include the dlls needed while 6.1.3 does. I also had success copying the dlls from an older version like 6.1.3 into the newer like 6.3.1 (Might give a warning but generally works as expected).
I have been having some troubles with the nuget package manager. Firstly, I was suddenly unable to search nuget. If I tried to install something through the packet manager console, I would get the following error
PM> Install-Package Microsoft.Bcl.Async
Install-Package : The ServicePointManager does not support proxies with the https scheme.
At line:1 char:16
+ Install-Package <<<< Microsoft.Bcl.Async
+ CategoryInfo : NotSpecified: (:) [Install-Package], NotSupportedException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
To solve this, I had to add a package source. Both of these seemed to work
http://www.nuget.org/api/v2/
http://packages.nuget.org/v1/FeedService.svc
This worked at the time. I searched and downloaded a package succesfully. The next morning however, I am now getting a different error. If I try and download anything from the nuget UI, I get a 404 message after I select the package that I want.
If I try and download something from the package manager console, I get the following error
The source at All [(Aggregate source)] is unreachable. Falling back to NuGet Local Cache at C:\Users\MYUSERNAMEHERE\AppData\Local\NuGet\Cache
Install-Package : Unable to find package 'Microsoft.Bcl.Async'.
At line:1 char:16
+ Install-Package <<<< Microsoft.Bcl.Async
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I asked a friend to try and download the package that I wanted, and he was able to without issue. Which leads me to believe this is a problem on my end. Any ideas?
I was using fiddler to inspect soap messages from a WCF service that I wrote, and I followed this tutorial to set it up
http://blogs.telerik.com/fiddler/posts/13-01-08/capturing-traffic-from-.net-services-with-fiddler
In this tutorial, it instructs you to add the following in to the machine.config file
<!-- The following section is to force use of Fiddler for all applications, including those running in service accounts -->
<system.net>
<defaultProxy
enabled = "true"
useDefaultCredentials = "true">
<proxy autoDetect="false" bypassonlocal="false" proxyaddress="http://127.0.0.1:8888" usesystemdefault="false" />
</defaultProxy>
</system.net>
When I removed this property, my Nuget issues went away
I am trying to install scaffolding package in VS2010 SP1 in MVC4(aim is to user MvcMailer), here are the command I run
PM> install-package T4Scaffolding
PM> install-package MvcScaffolding
and installing T4Scaffolding gives me this error:
Import-Module : Could not load file or assembly
'file:///path/packages\T4Scaffolding.1.0.5\tools\T4Scaffolding.dll' or
one of its dependencies. Operation is not supported. (Exception from
HRESULT: 0x80131515)
if I use installed it again, it installed but when I use Scaffolding command gives me this error
PM> Scaffolding Mailer.Razor UserMailer subs
The term 'Scaffolding' 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:12
+ Scaffolding <<<< Mailer.Razor UserMailer subs
+ CategoryInfo : ObjectNotFound: (Scaffolding:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I tried uninstalling and deleting the packages and re installing but no luck. I tried update command on both packages but nothing.
When I run import-module "dllpath"
I get same error message i.e.
Could not load file or assembly
'file:///path/packages\T4Scaffolding.1.0.5\tools\T4Scaffolding.dll' or
one of its dependencies. Operation is not supported. (Exception from
HRESULT: 0x80131515)
Tried restarting VS after uninstall, install, reinstall all possible but nothing changed.
What I am doing wrong.
EDIT: I have tried to use power shell
PS C:\Windows\system32> import-module
"path\T4Scaffolding.1.0.5\tools\T4Scaffolding.dll" Import-Module :
Could not load file or assembly
'file:///path\T4Scaffolding.1.0.5\tools\T4Scaffolding.d ll' or one of
its dependencies. This assembly is built by a runtime newer than the
currently loaded runtime and cannot be loaded. At line:1 char:14
+ import-module <<<< "path\T4Scaffolding.1.0.5\tools\T4Scaffolding.dll"
+ CategoryInfo : NotSpecified: (:) [Import-Module], BadImageFormatException
+ FullyQualifiedErrorId :
System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand
It gives error "This assembly is built by a runtime newer than the currently loaded runtime and cannot
be loaded." I believe here is the start failing point. Any idea? how to fix this first.
Solved, nothing new in solution but had to do a lot of search, hit and trial, I had VS2010 SP1, default installation. Project was loaded from network drive.
Import-Module : Could not load file or assembly 'file:///path/packages\T4Scaffolding.1.0.5\tools\T4Scaffolding.dll' or one of its dependencies. Operation is not supported.
Above error message comes from VS, because it can't load things from remote source.
Fix: Go to your Visual Studio devenv.exe location. i.e. default C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
in devenv.exe.config add line in runtime section i.e. :
<configuration>
<configSections>
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<requiredRuntime version="v4.0.30319" safemode="true"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
I wish error message was more proper at first place but I should also read more.
I am using ContosoUniversity example. I have just used Nuget to download and install code first migrations pakage. Whe I excecute update-database command it throws an error . Is there anything to do more than installing nuget package?
Update-Database : Could not load type 'System.Data.Entity.Infrastructure.DbContextInfo' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
At line:1 char:16
+ update-database <<<<
+ CategoryInfo : NotSpecified: (:) [Update-Database], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,System.Data.Entity.Migrations.Commands.MigrateCommand
Edit ,
Now I have installed ADO.NET Entity Framework 4.1 - Update 1 and now it throws an error
Update-Database : The project 'ContosoUniversity' does not contain or reference any contexts.
At line:1 char:16
+ update-database <<<<
+ CategoryInfo : NotSpecified: (:) [Update-Database], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,System.Data.Entity.Migrations.Commands.MigrateCommand
I have tried the scenario in microsoft blog but nothing changed. ( http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx )
Try installing the msi.
http://www.microsoft.com/download/en/details.aspx?id=26825
The second error that you are getting sounds like it s having problems identifying a context within your project. Make sure that you have a class that inherits from DbContext.
I would also check that your project is referencing the correct version of the Entity Framework - 4.1 Update 1. Depending on the project type, you should be able to locate the reference in question within the References folder within your project. You may need to click on the 'Show All Files' button (second from the left in the toolbar at the top of the Solution Explorer).
Once you have the reference selected, you will see information such as the path of the DLL and its version in the Properties pane (F4 if it is not already visible).
Edit: According to JTew below, a restart of Visual Studio is required.
Had the same error.
I had:
Installed EF 4.1 (the older version) via an .msi
Installed the newer version (EF 4.1 Update 1 Migrations Alpha 3) via NuGet
This error turned out to be the framework complaining because it was getting the older 4.1.0.0 from the GAC.
Uninstalling the older EF 4.1 did the trick.