Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.WinGet.Client throws System.InvalidOperationException: Attempt to update previously set global instance #3253

Merged
merged 2 commits into from
May 16, 2023

Conversation

msftrubengu
Copy link
Contributor

@msftrubengu msftrubengu commented May 16, 2023

Microsoft.WinGet.Client throws System.InvalidOperationException:“Attempt to update previously set global instance.” when used in winget configure with a resource from Microsoft.WinGet.DSC

This is because the custom AssemblyLoadContext implemented by the client module loads WinRT.Runtime.dll into the same processes where the configuration server already have WinRT.Runtime.dll loaded. When there are multiple versions of WinRT.Runtime.dll loaded in process this exception gets thrown. More info

The fix is to always load WinRT.Runtime.dll into the default assembly context, if its not loaded by the time our handler is executed and always return null in the Load implementation of the custom ALC.

This is a problem any PowerShell module that uses cswinrt will have (if there's another one out there)

Microsoft Reviewers: Open in CodeFlow

@msftrubengu msftrubengu requested a review from a team as a code owner May 16, 2023 03:27
@msftrubengu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@msftrubengu
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@msftrubengu msftrubengu merged commit cec3820 into microsoft:master May 16, 2023
@msftrubengu msftrubengu deleted the aclfix branch August 14, 2023 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants