Error Add-Migration in Visual Studio 2022, Entity Framework Core Version 6.06 and lower

Viewed 224

I cannot create the initial or any migration in my new Visual Studio 2022 install. This is a new project from scratch and everything is up to date. Any guidance would be appreciated.

PM> Add-Migration InitialSetup
Get-Interface : GetEnumerator must be called on the UI thread.
At C:\PROGRAM FILES\MICROSOFT VISUAL 
STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\NUGET\Modules\NuGet\profile.ps1:128 char:20
+     $service = Get-Interface $service $InterfaceType
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo     : NotSpecified: (:) [Get-Interface], COMException
  + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Get-Interface

The following exception occurred while trying to enumerate the collection: "GetEnumerator must be called on the UI thread.".
At C:\PROGRAM FILES\MICROSOFT VISUAL 
STUDIO\2022\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\NUGET\Modules\NuGet\profile.ps1:131 char:5
+   $service
+   ~~~~~~~~
  + CategoryInfo     : NotSpecified: (:) [], ExtendedTypeSystemException
  + FullyQualifiedErrorId : ExceptionInGetEnumerator

Add-Migration : You cannot call a method on a null-valued expression.
At line:1 char:1
+ Add-Migration Initial
+ ~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo     : InvalidOperation: (:) [Add-Migration], RuntimeException
  + FullyQualifiedErrorId : InvokeMethodOnNull,Add-Migration

This is my .csproj

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.6" />
   <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.6" />
   <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.5" />
   <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.6">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.5" />
</ItemGroup>
1 Answers

I want to thank Jeremy Lakeman and ErikE for their comments above. I am running .NET Core 6.0. This was the answer. I am running Windows 2012R2 and by default comes with PowerShell 4.0 which was never upgraded. By upgrading to PowerShell 5.1 fixes the PowerShell threading issue. I wish Microsoft would stop you if your PowerShell is too old when installing VS2022. For anyone else having this issue the download to update PowerShell is below

https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.2#upgrading-existing-windows-powershell

Related