efcore
efcore copied to clipboard
Visual Studio Package Manager Console EFCore Tools not working
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)
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.
/cc @bricelam
Old PowerShell version on Windows 8.1 ?
i had the same problem any solution please it s emergency ? and thank you
@ibtissemaloui Which Windows version and PowerShell version is in use?
Write-Host $PSversionTable.PSVersion
@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
Note for triage: See #28414.
This is failing before it ever gets to the EF code. This issue belongs in the NuGet/Home repo.
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 I suspect we will just tell everyone to stop using the PMC. See #28414.
Oh I see. I'm surprised NuGet is invoking our PowerShell function on a background thread. We don't create any threads here.
Old PowerShell version on Windows 8.1 ?
I am using this version, any recommendations please?
@IslamTareq0012 which version??
Windows 8.1 and PWS version 4.0
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
@IslamTareq0012 Any updates?
Yes it is working normally using dotnet CLI
@IslamTareq0012 did you try the PowerShell Update?
PowerShell Update worked for me.