I have a solution that uses NuGet to manage packages, and I also use the Package Manager Console for Entity Framework Migrations. Everything has worked fine for around a year.
This morning I removed a few projects from the solution as part of a reorganization. Now when I open the Package Manager Console, I am greeted with the error message
Set-DefaultScaffolder : Object reference not set to an instance of an object.
At E:\Dev\survey\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9
+ Set-DefaultScaffolder -Name CustomTemplate -Scaffolder
T4Scaffolding.Cus ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], NullR
eferenceException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet
What is causing this, and how can I fix it?
I installed Visual Studio 2012 SP2 a day or so after posting this issue, and it resolved itself.
Unsure whether SP2 fixed the underlying issue or just reset something, but either way the problem is resolved.
Related
I am using dotnet core 2 and visual studio 2019 and I have several db contexts. But I want to add a migration to the MedicalDbContext. And I have also more default projects. But the right default project is HepEngine. So I select that project als default project in Package manager.
And in the command prompt: PM>Add-Migration add-echeq-alert-action-extraProperty -c medicalDbContext -s
But then I get this error:
Add-Migration : Missing an argument for parameter 'StartupProject'. Specify a parameter of type 'System.String' and try again.
At line:1 char:72
+ ... Migration add-echeq-alert-action-extraProperty -c medicalDbContext -s
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Add-Migration], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Add-Migration
So what I have to change? Thank you
If you have more than one DataContext, you need to specify for which context the migration should be created. For my projects, I'm using this code
add-migration YOURMIGRATIONNAME -context MyDbContext
where MyDbContext is the name of your context.
You can find the documentation here.
I have just started using Visual Studio 2013 with EF6 and I have created a demo application with MVC 4. I tried to scaffold a controller but i keep getting an error. I have installed MVCScaffolding from the Package Manager Console and everything installed correctly including T4Scaffolding, T4Scaffolding.Core... however I keep getting this error. Please help me out
Invoke-Scaffolder : A positional parameter cannot be found that accepts argument 'Student'.
At line:1 char:1
+ Scaffold Controller Student -Repository
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Scaffolder], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,T4Scaffolding.Cmdlets.InvokeScaffolderCmdlet
Please tell me what I am doing wrong. Thanks A lot
I had a similar problem. Try with MVC 5.
Thank you for the suggestions. I solved this by using this command instead. Worked like a charm.
Install-Package MvcScaffolding -Version 1.0.8-vs2013 -Pre
I got it from this another question
I have a solution having 1 project.
Open Package Manager Console, run Install-Package MSBuildTasks
But it gave me an error below:
Install-Package : The current environment doesn't have a solution open.
At line:1 char:16
+ Install-Package <<<< MSBuildTasks
+ CategoryInfo : InvalidOperation: (:) [Install-Package], InvalidOperationExcep
tion
+ FullyQualifiedErrorId : NuGetNoActiveSolution,NuGet.PowerShell.Commands.InstallPackage
Command
I don't understand why it comes. Kindly suggest me waiting for reply. Thanks
I usually get this error because I created or opened a project (.csproj or other) that doesn't have a saved solution (.sln) associated with it.
If you go to File->Save All it should offer to save the solution somewhere. Save it and that makes the error go away for me.
I'm trying to enable migrations in MVC4, Entity Framework 5.00, however when I input the command it throws the following error:
Cannot determine a valid start-up project. Using project 'EFMigrations' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file://\\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.5.0.0\tool
s\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At \\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.6.0.0-beta1\tools\EntityFramework.psm1:669 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 \\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.6.0.0-beta1\tools\EntityFramework.psm1:670 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://\\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.
5.0.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At \\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.6.0.0-beta1\tools\EntityFramework.psm1:698 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
any and all help would be appreciated.
Running migrations from a network path is unsupported.
EF Team Triage: The migrations commands require full trust to run. Because you are running from a network share it looks like you are running in a lower trust level. In the past we have made the decision that the migrations commands would require full trust because it reduces the complexity of the implementation.
http://entityframework.codeplex.com/workitem/856
This means you have to put your project on a local drive, then you'll be able to run migrations.
It turns out that #Stijn's answer is indeed correct, However it doesn't provide a solution to the problem, the solution is to simple copy and paste the entire project into your Hard Drive and the command will work
I am trying to debug T4Scaffolding.Core Nuget package from outside Visual Studio 2012.
I am using Powershell ISE with Powershell 3.0 installed and run under CLRVersion 4.0.30319.
I first import several Nuget related items:
- Profile.ps1
- nuget.psm1
- NuGet.Cmdlets.dll
I am also setting the current location to set-location "\ClassLibrary1\"
and obtained the only DTE instance currently running (I previously opened MySolution in VS 2012 that has a class library and an asp.net MVC 4 application in it)
$dte = [runtime.interopservices.marshal]::GetActiveObject("visualstudio.dte")
I skipped importing Get-Project cmdlet from NuGet.Cmdlets.dll binary module, so I can create my own cmdlets: Get-Project
that gets my MVC project this way:
$project = $dte.Solution.Projects.Item("MvcApplication1\MvcApplication1.csproj")
I am able to step into init.ps1:
\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1
but the code fails when executing:
Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -SolutionWide -DoNotOverwriteExistingSetting
Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At line:1 char:1
+ Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTempl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet
I also tried pointing to my $project name (omitting -SolutionWide) with the same results.:
Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -Project ($project).Name -DoNotOverwriteExistingSetting
I could observe that EnvDTE.dll is loaded into Powershell ISE environment by using:
[System.Threading.Thread]::GetDomain().GetAssemblies()
Hopefully someone will be interested in achieving the same goal (stepping line by line through init.ps1 and install.ps1 of a Nuget package outside Visual Studio).
Thanks,
Rad
Stack Overflow: question I used as a starting point
I got same error message:
Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
but in different scenario. I was using scaffold in VS2015, installed T4Scaffolding.Core. Then I found the solution from this link
By installing Windows Management Framework 4.0 the error is gone and my scaffold works again.
Hopes this can help.