-
Notifications
You must be signed in to change notification settings - Fork 78
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
mscorlib is not referenced #121
Comments
sigh Yes. We'll probably go with load contexts in the end. When we created the module, we wanted to allow users to not use the bundled assembly, provided they go for a newer version or use their own. This was done mostly because on some organizations, opaque binary blobs are frowned upon. So we check if the assembly is loaded and only load it if it doesn't exist. But as you and others have come to notice, it sometimes bites back. I will allocate some time to make the needed changes. Will ping back here when I have something. |
thanks a lot. I feed you pain. I have the same task for a few modules, I maintain. |
Steps to reproduce this error:
If you supply any value to the |
Hi folks, could you give #132 a try? It should fix the conflict. |
short demo: # import platyps first
gabriel@rossak:~/powershell-yaml$ pwsh
PowerShell 7.4.5
PS /home/gabriel/powershell-yaml> import-module platyps
PS /home/gabriel/powershell-yaml> import-module ./powershell-yaml.psd1
PS /home/gabriel/powershell-yaml> exit
# import powershell-yaml first
gabriel@rossak:~/powershell-yaml$ pwsh
PowerShell 7.4.5
PS /home/gabriel/powershell-yaml> import-module ./powershell-yaml.psd1
PS /home/gabriel/powershell-yaml> import-module platyps List all ALCs: PS /home/gabriel/powershell-yaml> [System.Runtime.Loader.AssemblyLoadContext]::All | fl *
Assemblies : {System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, pwsh, Version=7.4.5.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35,
System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, System.Management.Automation, Version=7.4.5.500, Culture=neutral,
PublicKeyToken=31bf3856ad364e35…}
IsCollectible : False
Name : Default
Assemblies : {YamlDotNet, Version=13.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, jbtx4qo5.tda, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null}
IsCollectible : True
Name : powershellyaml
And the assemblies from both ALCs: PS /home/gabriel/powershell-yaml> import-module platyps
PS /home/gabriel/powershell-yaml> import-module ./powershell-yaml.psd1
PS /home/gabriel/powershell-yaml> $gac = ([System.Runtime.Loader.AssemblyLoadContext]::All | ? {$_.Name -eq 'Default'})
PS /home/gabriel/powershell-yaml> $pwshY = ([System.Runtime.Loader.AssemblyLoadContext]::All | ? {$_.Name -eq 'powershellyaml'})
PS /home/gabriel/powershell-yaml> $pwshY.Assemblies | ? {$_.Location -like "*YamlDotNet.dll" }
GAC Version Location
--- ------- --------
False v4.0.30319 /home/gabriel/powershell-yaml/lib/netstandard2.1/YamlDotNet.dll
PS /home/gabriel/powershell-yaml> $gac.Assemblies | ? {$_.Location -like "*YamlDotNet.dll" }
GAC Version Location
--- ------- --------
False v4.0.30319 /home/gabriel/.local/share/powershell/Modules/platyPS/0.14.2/YamlDotNet.dll
|
Given that powershell-yaml is written in powershell and not C#, this approach in using ALC may look strange, but it allows us to load assemblies in a different context (on powershell 6+) and use the types from the assemblies in that context. It's not the usual way to use ALC, but it seems to work for the dependencies we need. On powershell < 6 we still use the GAC. |
Hello,
First of all: Thank you for this module.
When I import platyPS, before I load powershell-yaml, I get the following issue:
If I load powershell-yaml before platyPS, the import of platyPS I get:
I found out, that both modules use YamlDotNet.dll but in different versions. Both outdated, but this is not the issue.
I think, there are patterns to solve this: https://github.com/jborean93/PowerShell-ALC contains an example.
The text was updated successfully, but these errors were encountered: