EF exception after upgrade to Visual Studio 2017 - asp.net

I have this asp.net core project (targeting standard framework) which I used to work on with VS 2015. I'd recently migrated the project to VS2017 and everything was going just fine until I needed a change in the db and as I ran the add-migration command I got this exception:
Exception calling "SetData" with "2" argument(s):
+ $domain.SetData('project', $project)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
I've seen people making all sort of suggestions here on SO like running VS as admin or upgrading EF libraries. those solutions did not work for me.
Also there's only one project in the solution so the default project in package manager console can't be wrong.

Related

add-migration : Cannot bind argument to parameter 'Path' because it is null

I want to enable migration in visual studio 2017. When I run it, I'm getting an error. The error message is:
add-migration : Cannot bind argument to parameter 'Path' because it is
null. At line:1 char:1
+ add-migration ApplyAnnotationsToCustomerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Migration], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-Migration.
I tried to uninstalling and reinstall EntityFramework and it didn't work.
Also my startup project is set to the project with EF.
nothing worked!!
Ohh... spent hours trying to figure this one out. I tried all the suggestions I could find and even tried what you did uninstalling and reinstalling EF. Nothing seemed to work and it was really frustrating. In the end what ultimately worked for me was how I uninstalled and reinstalled EF!
Uninstall:
PM> Uninstall-Package EntityFramework -Force
Reinstall EntityFramework:
PM> Install-Package EntityFramework -Pre
Source: https://entityframework.net/knowledge-base/14410987/entity-framework-code-first-migration-error

Error while installing Microsoft.AspNet.WebApi.OwinSelfHost from NuGet

I'm trying to get this: http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api running.
Therefore I need to put this into NuGet package manager console
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
I got the following Error
Install-Package : Das angegebene Argument liegt außerhalb des gültigen Wertebereichs. (in english: The given argument is out of the valid value range.)
parametername: supportedFrameworks
at line:1 position:16
+ Install-Package <<<< Microsoft.AspNet.WebApi.OwinSelfHost
+ CategoryInfo : NotSpecified: (:) [Install-Package], ArgumentOutOfRangeException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
You can find this package's dependencies on https://www.nuget.org/packages/Microsoft.AspNet.WebApi.OwinSelfHost/5.2.3 .
I continued to locate where the error comes from and found that the Newtonsoft Json package could be the problem. But since there are no dependencies or subpackages given, I cannot go any further which let me post my question here:
What to do, to solve this problem?
My project's target framework is .NET 4.5.1 and I use VS2013 with recent update and NuGet manager V2.8 (also the recent version for VS2013, I think).
Edit1: I found that e.g. my Microsoft.CSharp reference is to Microsoft.CSharp V4.0.0.0 ... for recent Json versions Microsoft.CSharp V4.0.1 or higher is needed. How do I update this? And why do I have to do this?

Add-Migration command not working in EF 7 for UWP app

I'm following getting started with EF 7 for UWP apps official tutorial.
When I'm at Add-Migration MyFirstMigration, it throws following error:
PM> Add-Migration MyFirstMigration
Add-Migration : Exception calling "CreateInstanceAndUnwrap" with "8" argument(s): "Could not load file or assembly 'AppShellProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. An attempt was made to load a program with an incorrect format."
At line:1 char:1
+ Add-Migration MyFirstMigration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException
+ FullyQualifiedErrorId : BadImageFormatException,Add-Migration
Has anyone figured out any workaround?
Great job #Anil. :)
Actually, since this kind of issue may be related to Visual Studio tools or NuGet. By searching "CreateInstanceAndUnwrap Add-Migration" in EF repository on GitHub, you will see some issues there. If you cannot find any existing issues next time, as same as the questions(project.json, project type and etc. ) I asked, try to find out what's the difference between your steps/configurations and the tutorial will be helpful and you will have more info to get a quick answer.
I believe #bricelam has pointed out the issue you encountered, and no one is more familiar with EF7 than him. I want to pick some key messages from #bricelam in that issue as the ending:
Correct, the Migration commands won't work with x64 assemblies. The current implementation executes inside of an AppDomain created from VS (devenv.exe) which is a 32-bit process.
you'll have to use x86 at design-time.

Can't get AWS Elastic Beanstalk Command Line Tool to work on Windows 8. Get the following PowerShell error?

Add-Type : Cannot add type due to the following exception: Compiler executable
file csc.exe cannot be found.. Verify that version 3.5 of the Microsoft .NET
Framework is installed. On 64-bit versions of Windows, the WOW64 component is
also required.
At C:\Users\Albert\Documents\WindowsPowerShell\Modules\AWSDevTools\AWSDevTools.
ps1:315 char:1
+ Add-Type -Language CSharpVersion3 -TypeDefinition $awsSource
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], InvalidOperationEx
ception
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Power
Shell.Commands.AddTypeCommand
PATH set to %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\wamp\bin\php\php5.4.3;C:\Program Files\Java\jre7\bin;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd;C:\Program Files\AWS-ElasticBeanstalk-CLI-2.4.0\eb\windows;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\Microsoft.NET\Framework\v4.0.30319
I'm following this tutorial online
Thanks
You need to install .NET 3.5 on your Windows 8 machine as it isn't installed by default. Open up the Control Panel, select Programs then Program and Features. Select the "Turn Windows Features on or off" link on the left and select .NET Framework 3.5 and press OK.

Enabling Code First Entity Framework VS Web Express 2012

I am trying to enable Code First in my Visual Studio Web Express 2012. From what I have read so far I have to use the Package Manager Console and the command Enable-Migrations. When I do this I get the following error.
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398 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 E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:399 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:///E:\Working\wingtoysdl\C#\packages\EntityF
ramework.5.0.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+ $domain.CreateInstanceFrom <<<< (
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
As you can see it is a very large error making it very hard to google and troubleshoot. Does anyone have any ideas on how I can fix this?
I've run into this issue twice now. Both times I've had to uninstall entity framework then re-install it for each project in the solution. One thing that took me a while to figure out the second time I did this is that I had to re-start Visual Studio (2012) after re-installing Entity Framework (or I continued to get the "Could not load file or assembly '[path]\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll'" error).
To get to the Package Manager Console go to: Tools -> Library Package Manager -> Package Manager Console
In the Package Manager uninstall Entity Framework for each project (I selected each project from the Default Project dropdown at the top of the Package Manager Console):
Uninstall-Package EntityFramework -Force
Then install it for each project:
Install-Package EntityFramework
At this point attempting to run the Enable-Migrations command gave the error still, until I closed and restarted Visual Studio. Then it was successful, as was the Update-Database command (after setting AutomaticMigrationsEnabled to true in the Migrations.Configuration file).
Had the same issue on two different machines while using projects on a network drive. This answer fixed it for me.
This may be a late answer but this seems like it could be a permissions/access problem.
Make sure that your project is not being opened from a mapped drive or similar.
If you are on a corporate network and logged into a domain, it is very likely that your user profile does not actually sit on your local computer but rather on the server. This will cause the same problem.
Try copy the project to your local c: and try again.
My problem was caused by some projects in my solution not being updated to the same version as other projects. When I ensured all were on the same EF version, it began working.
So I had the same problem for a while, I was unpacking a working project and got the error as I tried to enable migrations. It was simply fixed by using 7-Zip instead of the default unzipper from windows 10
I was also encounter the same problem so I started to check the possible things could go wrong and I found 2 different versions of entity framework is get installed somehow.
To confirm I goto Tools> NuGet package manager solution > Manage NuGet packages > Consolidate.
Have a look below images.
In this picture you may clearly see the different version is installed
in this picture I am agree to update the Entity Framework from 6.2.0 to 6.4.4
I had the same issue and in my case it was network drive problem. When I copied my project in local drive it worked fine.

Resources