efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Visual Studio Package Manager Console EFCore Tools not working

Open vsfeedback opened this issue 2 years ago • 19 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] Windows 8.1 Visual Studio 2022 17.2.5 Nuget Package Manager 6.2.1

Every time I try to use the EFCore tools I get the following error -

Get-Interface : GetEnumerator must be called on the UI thread. At C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\ENTERPRISE\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\ENTERPRISE\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
    
    

I have tried reinstalling Visual Studio but no luck. All help greatly appreciated

Thanks


Original Comments

Feedback Bot on 6/24/2022, 03:58 AM:

(private comment, text removed)

Donnie Goodson [MSFT] on 7/2/2022, 01:06 AM:

(private comment, text removed)

Feedback Bot on 7/7/2022, 07:50 PM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Jul 09 '22 18:07 vsfeedback

Donnie Goodson commented 17h ago

@Kevin Pilch @Arthur Vickers No, our PM Console hasn't changed. Your psm1 that I linked before is using APIs from the VSSDK which has particular threading requirements. Since this is a PowerShell script, it can't take advantage of the VS Threading analyzers, but looking at the rules in those analyzers, it's clear that this rule would result in an analyzer warning:

[Microsoft.VisualStudio.Shell.Interop.*] [line 3 from vs-threading.MembersRequiringMainThread.txt]

This is saying these APIs must be executed on the main thread. You can find this rule in package Microsoft.VisualStudio.SDK.Analyzers/16.10.10 , in the Build\AdditionalFiles\ folder, in the analyzer file: vs-threading.MembersRequiringMainThread.txt.

Our best guess, based on the error, "GetEnumerator must be called on the UI thread.", is that this service belongs to the Project System team. Perhaps this service was more forgiving in the past regarding being on the UI thread, and now it is enforcing that requirement. You would need to reach out to that team verify the correct usage of this service, or if anything recently changed. We think this is Michael Eng's team, but I'm not sure.


Kevin Pilch commented Yesterday

@Donnie Goodson @Arthur Vickers Moving to NuGet Clients. Did something change with the way the package manager invokes things? I don't believe EF ever explicitly switches threads, and this has always worked.


Donnie Goodson commented Wednesday

(edited)

Hello @Kevin Pilch & @Arthur Vickers, I'm moving this regression ticket to you because we found code in your repo that makes us believe this issue is coming from your method GetVsHierarchy at efcore/EntityFrameworkCore.psm1 at main · dotnet/efcore (github.com). Our understanding is Get-VSService is being called on a background thread which is not supported by the VS API.

ajcvickers avatar Jul 09 '22 18:07 ajcvickers

/cc @bricelam

ajcvickers avatar Jul 09 '22 18:07 ajcvickers

Old PowerShell version on Windows 8.1 ?

ErikEJ avatar Jul 10 '22 13:07 ErikEJ

i had the same problem any solution please it s emergency ? and thank you

ibtissemaloui avatar Jul 11 '22 06:07 ibtissemaloui

@ibtissemaloui Which Windows version and PowerShell version is in use?

Write-Host $PSversionTable.PSVersion

ErikEJ avatar Jul 11 '22 07:07 ErikEJ

@ibtissemaloui If the PMC tooling is not working, then please use the dotnet command line tooling--see https://docs.microsoft.com/en-us/ef/core/cli/dotnet

ajcvickers avatar Jul 11 '22 09:07 ajcvickers

Note for triage: See #28414.

ajcvickers avatar Jul 11 '22 09:07 ajcvickers

This is failing before it ever gets to the EF code. This issue belongs in the NuGet/Home repo.

bricelam avatar Jul 11 '22 18:07 bricelam

The customer report was when they ran Add-Migration from Package Manager Console, which certainly is EF Code. Unfortunately I don't know how to get a "powershell call stack", so I don't know how to check what functions are being called between Add-Migration to get to Get-VSService, but it doesn't change the fact that EFCore is calling VSSDK APIs in powershell: https://github.com/dotnet/efcore/blob/c146f7a38e126f5001cd3383d4b70f250fd6bf3c/src/EFCore.Tools/tools/EntityFrameworkCore.psm1#L1491

VS has "threading rules" that callers of the VS SDK should adhere to: https://github.com/microsoft/vs-threading/blob/main/doc/threading_rules.md There are Roslyn analyzers that will warn when .NET code is written against the VS SDK, but since EFCore is doing this powershell, you don't get the advantage of those analyzers.

I'm sorry if this is coming off as "nuget team doesn't want to help", but the API contract is between the caller of the API (EFCore) and the owner of the API (IVsSolution, maybe others?). There exist VS services that can be called on background threads, so it would harm perf for NuGet to systemetically run Get-VSService on the UI thread, but even if we did, once we return to the caller on the background thread, it would still be your responsibility to switch to the UI thread to call those VS SDK APIs.

zivkan avatar Jul 11 '22 18:07 zivkan

@zivkan I suspect we will just tell everyone to stop using the PMC. See #28414.

ajcvickers avatar Jul 11 '22 18:07 ajcvickers

Oh I see. I'm surprised NuGet is invoking our PowerShell function on a background thread. We don't create any threads here.

bricelam avatar Jul 11 '22 22:07 bricelam

Old PowerShell version on Windows 8.1 ?

I am using this version, any recommendations please?

IslamTareq0012 avatar Jul 12 '22 14:07 IslamTareq0012

@IslamTareq0012 which version??

ErikEJ avatar Jul 12 '22 15:07 ErikEJ

Windows 8.1 and PWS version 4.0

IslamTareq0012 avatar Jul 12 '22 15:07 IslamTareq0012

You can try to update to 5.1 https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell#upgrading-existing-windows-powershell - not convinced it works.

Or you can use the dotnet CLI tools

ErikEJ avatar Jul 12 '22 15:07 ErikEJ

@IslamTareq0012 Any updates?

ErikEJ avatar Jul 13 '22 08:07 ErikEJ

Yes it is working normally using dotnet CLI

IslamTareq0012 avatar Jul 13 '22 15:07 IslamTareq0012

@IslamTareq0012 did you try the PowerShell Update?

ErikEJ avatar Jul 13 '22 15:07 ErikEJ

PowerShell Update worked for me.

NewGHUser4321 avatar Aug 08 '22 15:08 NewGHUser4321