Open jdhitsolutions opened 1 year ago
As I was writing this issue, I came up with a culprit. The BurnToast module uses the same assembly.
If I load this module after the Winget module, I get an error:
Write-Error: Failed to load library C:\Program Files\WindowsPowerShell\Modules\burnttoast\0.8.5\lib\Microsoft.Windows.SDK.NET\WinRT.Runtime.dll: Assembly with same name is already loaded
If I load the BurnToast module first, I can load the Winget module without error. I only get the error when I try to run a command. The import process should throw the same type of exception that the BurntToast module does.
It looks like the BurnToast module and Winget module use the same version of WinRT.Runtime.
Is this happening in Windows PowerShell or in PowerShell 7?
We have some missing assemblies to hunt down to get everything working correctly in Windows PowerShell.
I'm using PowerShell 7 for this.
Which version of BurnToast are you using? This won't work with the latest non prerelease version (0.8.5), but will do for 1.0.0
Pre release version
PS C:\Dev> import-module BurntToast
PS C:\Dev> get-module BurntToast | select-object -Property Version
Version
-------
1.0.0
PS C:\Dev> import-module microsoft.winget.client
PS C:\Dev> Get-WinGetUserSettings
Name Value
---- -----
visual {[progressBar, rainbow]}
installBehavior {[disableInstallNotes, True]}
experimentalFeatures {[configuration, True]}
$schema https://aka.ms/winget-settings.schema.json
source {[autoUpdateIntervalInMinutes, 1]}
PS C:\Dev> get-module microsoft.winget.client | select-object -Property Version
Version
-------
0.2.2
PS C:\Dev> [Reflection.AssemblyName]::GetAssemblyName("C:\Users\rubengu\Documents\PowerShell\Modules\BurntToast\1.0.0\lib\Microsoft.Windows.SDK.NET\WinRT.Runtime.dll")
Version Name
------- ----
2.0.0.0 WinRT.Runtime
Release version
PS C:\Dev> import-module burntToast -RequiredVersion 0.8.5
PS C:\Dev> import-module microsoft.winget.client
PS C:\Dev> Get-WinGetUserSettings
Get-WinGetUserSettings: The type initializer for '<Module>' threw an exception.
PS C:\Dev> [Reflection.AssemblyName]::GetAssemblyName("C:\Users\rubengu\Documents\PowerShell\Modules\BurntToast\0.8.5\lib\Microsoft.Windows.SDK.NET\WinRT.Runtime.dll")
Version Name
------- ----
1.1.0.0 WinRT.Runtime
For more context, the winget modules uses their own custom AssemblyLoadContext to load binaries there with the goal to avoid these kinds of conflicts, but sadly WinRT.Runtime.dll can't be loaded in a custom ALC. See more info in #3253. Because of that we explicitly load it in the default context.
I'm still using 0.8.5
. I'm not ready to jump to the pre-release version. It looks like options are extremely limited, so I'll stick to using the winget PowerShell module in a separate session.
I created an issue in CsWinRT https://github.com/microsoft/CsWinRT/issues/1371
Brief description of your issue
I am running version 0.2.2 of the Microsoft.Winget.Client module, although I had this problem in the earlier version. In a PowerShell 7 session running with no profile, I can import and use the module with no problem. In my normal session, with a profile, I can import the module with no errors. But when I run any command, I get the error
The type initializer for '<Module>' threw an exception.
I've narrowed down at least part of the problem to the fact that not all DLLs are getting loaded. I think the
WinRT.Runtime
is the culprit. I tried manually adding it in my PowerShell session and it fails.Environment