Closed matzter closed 1 year ago
Hi @matzter ,
Yes, both powershell-yaml
and Az.Aks
load YamlDotNet.dll
, although different versions. This module however, checks before attempting to load the assembly. That way, if the assembly is already loaded and has all the required types, it does nothing. Once an assembly is loaded in the current AppDomain
it can't really be unloaded without unloading the AppDomain
(closing the powershell process).
This is not an issue I can fix in this module. This is something that the Az.Aks
module needs to address. YamlDotNet is a third party library that can already exist on a system and may be of a different version then what ships with a module. If the version we try to load differs from the one that is already loaded in the current app domain, you get the error you mentioned.
The version Az.Aks
loads is:
YamlDotNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e
The version that powershell-yaml
tries to load is:
YamlDotNet, Version=13.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e
hence the error.
This is why I ended up using the Load-Assemblies.ps1 script instead of using RequiredAssemblies directive in the psd1
file that Az.Aks
uses. It made no sense to require a strict version of YamlDotNet.dll
(as long as some basic guardrails were used, like checking for needed types), especially considering that users may install their own library and load it before loading powershell-yaml
. It also made sense to use a method that offered some sort of idempotency, which RequiredAssemblies
didn't seem to offer in cases where the assembly version differed.
A really shaky workaround would be to load Az.Aks
first, then load powershell-yaml
. Powershell-yaml should work with that version and skips trying to load the assembly if it's already loaded.
I suggest also opening an issue against Az.Aks
. They use a really old version of the YamlDotNet.dll
assembly.
Thank you very much for the detailed and prompt response. I created an incident for az.aks https://github.com/Azure/azure-powershell/issues/21895
I don't understand enough how this works, but I have this conflict for over an year now and finally figured what is causing it. If powershell-yaml module is loaded, Az.Aks can not be imported anymore.
PowerShell 7.3.4
This has been executed on a fresh VM, no other tools or modules have been installed, and the issue can be reproduced.