I can't get Scaffold-DbContext to work on a EFCore 1.1 application.
PM> Scaffold-DbContext -Connection "'Server=.;Database=testsite;User Id=sa;Password=Password1234;'" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir EFContext -Context ApplicationDbContext
This is the error that it's giving:
Scaffold-DbContext : Cannot bind argument to parameter 'Path' because it is an empty string.
At line:1 char:1
+ Scaffold-DbContext
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Scaffold-DbContext], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Scaffold-DbContext
Not exactly a forthcoming error message so I ran just Scaffold-DbContext and it gives me this error after prompting for the Provider. The provider I'm trying to use is Microsoft.EntityFrameworkCore.SqlServer.
In my case I fixed it installing Microsoft.EntityFrameworkCore.Tools. Make sure to close and reopen VisualStudio. (Do not forget to add the -force flag to the end in order to reapply the changes from scratch)
Example:
Scaffold-DbContext
"Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force
So, my dependencies looks like:
Microsoft.AspNetCore.All
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools
After that it worked as expected.
If you have multiple project in your solution you can try to add the option
-StartupProject "nameofyourprojectstartup" with the project name that have to run this command.
I had the same error when trying to run "add-migration" with multiple project (Docker support) in my solution.
Related
I'm working on a .NET Standard application that utilizes Entity Framework Core 3.1.2. We use code-first migrations at my company.
When I execute Add-Migration with a ConnectionString parameter as follows:
add-migration MyMigration -ConnectionString "data source=servername;persist security info=True;user id=MyUserID;password=MyPassword"
I get the following error:
Add-Migration : A parameter cannot be found that matches parameter name 'ConnectionString'.
At line:1 char:52
+ ... ration ShuntReportConditionIDAndTitleFields -ConnectionString "data s ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Migration], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Add-Migration
Why do I get this error? This documentation site states that -ConnectionString is a valid parameter for the Add-Migration command. Has something changed with the EF platform?
The documentation site is for EF 6, and you are using EF Core!
I've upgraded to dotnet sdk version 3.1 and am trying to publish my powershell module. I am using powershell 5.1.
I run the command:
Publish-Module -Path "C:\sources\myModules\InstallationUtils\" -NuGetApiKey "xxxxxxx" -Repository internal.packages.org"
and get the error:
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
Successfully created package
'C:\Users\xxxxxx\AppData\Local\Temp\158464074\myModules\InstallationUtils\InstallationUtils.1.4.8.nupkg'.
C:\Program Files\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error :
Index was outside the bounds of the array.
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:10944 char:17
+ ... Publish-PSArtifactUtility #PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility
Is anyone have similar issues and managed to fix it?
thanks
I have a work around, which involves replacing the old version of version nuget.exe in
C:\Users\xxxxx\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
with the latest version of nuget.exe .
I found the work around on SQLDBAWithABeard but I am hoping that there is a better solution than this?
I was following a tutorial about the asp.net-mvc . I have been stuck in enable-migrations nuget package manager
I was first haunted by the enable-migrations cmd not found error so for that purpose I followed from the following link : Package Manager Console Enable-Migrations CommandNotFoundException only in a specific VS project
enable-migrations : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:1
+ enable-migrations
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Enable-Migrations], ParameterBindingValid
ationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Enable-Migra
tions
I did my best to find but did not found any answer on this . Can someone please help me on this matter ?
In order to enable the migrations with code first, a database must exist, try and build your application, add some data to the tables, re-build the application and try again
Currently I trying to separate my data model into a different project in the same solution, with code first. If I only have one project with EF( 6.1.3 ) installed, migration ( Enable-Migration, Add-Migration ) work as intended.
But as I add an other project and install EF packet, if i try Enable-Migration, I've got this error:
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:713 char:27
+ $toolsPath = Join-Path <<<< $installPath tools
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 char:73
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<< $ToolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
You cannot call a method on a null-valued expression.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 char:50
+ $dispatcher = $utilityAssembly.CreateInstance <<<< (
+ CategoryInfo : InvalidOperation: (CreateInstance:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Join-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\projects\IMS 2\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:810 char:19
+ (Join-Path <<<< $runner.ToolsPath EntityFramework.PowerShell.dll),
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
EF seems to work fine in both of the projects. Reinstalling EF to either or both of the projects did not solve it. Any solution in mind?
EDIT: I started a new solution with 3 projects, 1. for the basecontext( public class BaseContext<TContext> : DbContext where TContext : DbContext ... ), 2. for base classes, and 3. for creating a context based on base context and the classes. If i put ef in only one then migrtation works, or at least tells me thet it can't find a context, but if i install it into more then one, then it's producing the error again.
I found the same problem today and I had to uninstall the EF and install again.
PM> Uninstall-Package EntityFramework -Force
PM> Install-Package EntityFramework -Pre
Ok, solved it, the problem was not EF, or VS2015, but my Windows 7, since it come with PowerShell 2, but EF or VS required PowerShell 3 to work properly. After updating to it the errors was gone.
Then i run ito this bug: https://connect.microsoft.com/VisualStudio/feedback/details/1302181/add-migration-bug what is currently under review.
It seems like that it's caused by some configuration bug in the VS2015 RC release. Rolled back to VS13 with powershell 2, reinstalled the related nuget packages, and it's working fine now.
I'm trying to create powershell management scripts for my EF6 based website, but I'm struggling to create a DbContext to access my entities.
Following PowerShell App.Config, I'm doing the following to load my dll, set the config file for the current app domain and instantiate my DbContext.
Add-Type -AssemblyName System.Configuration
[appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", "path.to.web.config")
[Reflection.Assembly]::LoadFrom("MyProject.Dll")
$ctx = New-Object MyProject.MyDbContext
$ctx
I'm able to load the dll, and can inspect that it finds the MyProject.MyDbContext class, and it seems to be able to create the object as well, but upon executing the last statement I get a TargetInvocationException
format-default : Exception has been thrown by the target of an invocation.
+ CategoryInfo : NotSpecified: (:) [format-default], TargetInvocationException
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.FormatDefaultCommand
I've tried catching the TargetInvocationException, but it seems to escape my try-catch somehow.
Any ideas?
It turns out that PowerShell.exe uses .NET v2.0 by default. Following cmo999's answer (note that it's not the accepted answer on that question), it's possible to run powershell.exe under v4.0 by modifying powershell.exe.config.