Add-Migration throws Win32Exception in VS Community 2022 - c#

I have a simple WebAPI project (.NET 6) using VS Community 2022 and I'm trying to add a migration in package manager console with the following command:
add-migration initial
which leads to the following error:
add-migration : Exception calling "Start" with "1" argument(s):
"The specified executable is not a valid application for this OS platform."
At line:1 char:1
+ add-migration initial
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:)
[Add-Migration], MethodInvocationException
+ FullyQualifiedErrorId : Win32Exception,Add-Migration
The exact same code runs on VS Community 2019 (.NET 5) without any issues, so I don't think it has anything to do with the code.
Even an empty WebAPI project in VS 2022 (with Microsoft.EntityFrameworkCore.Tools package installed) throws the same Win32Exception.
On the other hand, in VS 2019, the empty WebAPI project (with Microsoft.EntityFrameworkCore.Tools package installed) gives the "No DbContext was found" error, which is expected.
I've also tried reinstalling the packages and restarting visual studio and it didn't work. I'd appreciate your help!
I have installed the following NuGet Packages:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer

I think you are facing this issue when you trying to scafolding database constraints for that while writing the connection string. Replace "\\" with "\"
Example:- Local\\database should be Local\database

Related

Stuck in asp.net core tutorial. Trying to use package manager console to add EF Core SQL Server provider does not work

I am following this beginners tutorial on Microsoft's site.
At this step...
In the PMC, run the following command:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
When I enter that command I get these messages and errors..
PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer
Restoring packages for C:\projects\LazerbaseASPNET\LazerbaseASPNET\LazerbaseASPNET.csproj...
GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/index.json
OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/index.json 208ms
GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/6.0.7/microsoft.entityframeworkcore.sqlserver.6.0.7.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.sqlserver/6.0.7/microsoft.entityframeworkcore.sqlserver.6.0.7.nupkg 71ms
Installed Microsoft.EntityFrameworkCore.SqlServer 6.0.7 from https://api.nuget.org/v3/index.json with content hash D9YV3hc3VSN1qrfdrZcKtMcRLT6bUqj8KtaUdkmO1CH/+meL+8z3Rge5iPhwQ4ol2AwPQlQYVPTTajf9ulSFGg==.
Install-Package : NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 6.0.7 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.SqlServer 6.0.7 supports: net6.0 (.NETCoreApp,Version=v6.0)
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for 'LazerbaseASPNET'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:03.2286177
Seems the important one is this...
Package Microsoft.EntityFrameworkCore.SqlServer 6.0.7 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package
Microsoft.EntityFrameworkCore.SqlServer 6.0.7 supports: net6.0
This tutorial is for asp.net core 3.1.. It seems to be the one they recommend for beginners also. I am at a impass and have no idea how to proceed.
EDIT:
I think this is cus I used Visual Studio 2019 which I already had installed for Unity.. asp.net core 3.1 was the only option available for a new project... I think I need to wipe the existing server from azure, download Visual Studio 2022 and start again with a asp.net core 6 app ?
You can try to install entity framework core through the nuget package manager.
Rightclick on your project -> Manage Nuget packages. Before installing select the correct version from the dropdown for the netcore app version you are running.
I think this is cus I used Visual Studio 2019 which I already had installed for Unity.. asp.net core 3.1 was the only option available for a new project.
The solution is wipe the existing server from azure, download Visual Studio 2022 and start again with a asp.net core 6 app.
FML.
I also want to point out that this tutorial is wrong. Earlier in it it says requirement is Visual Studio 2019 16.4 or later.
I did read this and checked the version of Visual studio I had installed, I met the requirements so I kept going.

C# Double Ended Queue for Net 2.1

I found Stephen Cleary's double ended queue for NET 2.0. When I install it with pm in visual studio Net 2.1 I get this error:
"PM> Install-Package Nito.Collections.Deque -Version 1.0.4
Install-Package : Project 'Default' is not found.
At line:1 char:1
+ Install-Package Nito.Collections.Deque -Version 1.0.4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Default:String) [Install-Package], ItemNotFoundException
+ FullyQualifiedErrorId : NuGetProjectNotFound,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand"
It appears pm was in a bad state. I rebooted Visual Studio 2017 and the default project appeared. I was able to install the deque package.
The comments helped me to solve this issue by pointing out to look for where the default project is

add-migration fails due to incompatability of packages

I have a connection to a SQL Server database I created in Micrososft SQL Server Management Studio. I am connected using my current ip.
The day I opened the connection and the database I also created a table using migrations and Entity Framework, and the table was created successfully.
Returning to work after turning off the computer at night and then back at the morning, I try to perform add-migration in PM Console I get the error:
Your startup project 'TowerOfPower' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
Weird, but then when I try installing the package
Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0
I get the error:
Install-Package : Could not install package 'Microsoft.EntityFrameworkCore.Design 2.1.0'. You are trying to install this package into a project that targets
'.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
So I tried to fix this by installing other packages as suggested on the web, but still got the last error I mentioned for all of them.
I think there is a big contradiction about your framework types. Firstly, If you develope .NetCore project, you have to use EfCore for ORM progress. In .NetFramework project, you have to use Entity Framework.
If we look at the latest error message,
You are try to load incorrect nuget project. According to error message you are try to install EntityFrameworkCore packege to ".NETFramework,Version=v4.0'" For this framework you have to use Install-Package EntityFramework -Version 6.2.0
Lastly, If you use multiple project in single solution, you have to be sure about project frameworks types (exp: .Net or .NetCore)
When you use Package Manager Console, you have to chose correct project in Default Project ComboBox

Nuget package installation fails although package should be supported

I am trying to install the package Microsoft.Extensions.DependencyInjection.Abstractions in my Visual Studio 2013 solution as part of a Sitecore installation. The solution has .NET target framework 4.5.2.
The installation fails with
Install-Package : Could not install package 'Microsoft.Extensions.DependencyInjection.Abstractions 1.0.0'. You are trying to install this package into a project that targets
'.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the
package author.
At line:1 char:1
+ Install-Package Microsoft.Extensions.DependencyInjection.Abstractions -Version 1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I have tried performing the installation in a completely new, empty solution but the installation still fails.
According to the link, there is a dependency to .NETStandard 1.0 but this should be supported by 4.5 according to this.
JaCraig's commment helped me solve this: I upgraded Nuget Package Manager from 2.8 to 2.12. Afterwards, there were no problems with the installation.

'System.Net.Http' already has a dependency defined for 'System.Runtime'

I'm trying to install the MaxMind MinFraud package via NuGet. Whenever I try, I get the following back -
PM> install-package MaxMind.MinFraud
Attempting to resolve dependency 'System.Net.Http (≥ 4.0.0)'.
install-package : 'System.Net.Http' already has a dependency defined for 'System.Runtime'.
At line:1 char:1
+ install-package MaxMind.MinFraud
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
A few other similar questions here suggested restarting VS, manually adding a reference to System.Net.Http and clearing NuGet Package Cache, and changing the target framework to 4.6.2 (originally 4.5), all of which did not work for me.
Any ideas on what I can try next?
I installed this package successful in my Visual Studio 2015 Update 3 project with NuGet Package Manager 3.4.4.
So please make sure your are using the latest version of Visual Studio 2015 and NuGet Package Manager.

Categories