I'm working in Windows 10 x64, PowerShell version 5.1.
I've got multiple versions of a .NET Framework 4.0 assembly (.dll) written in C# (by myself). Assemblies are not signed. Their versions are set in AssemblyInfo.cs
via [assembly: AssemblyVersion("X.X.X.X")]
. The [assembly: AssemblyFileVersion("X.X.X.X")]
tag does not exist in my AssemblyInfo.cs
! These assemblies are used in a regular .NET Framework application, they're not specialized PowerShell modules nor they have manifest files.
I use this assembly in some PowerShell scripts to create objects and call methods from it.
I've got two versions of this assembly, let's say 1.1.1.100
and 1.2.1.100
. When I import let's say 1.1.1.100
version in PowerShell via Import-Module "D:\path\to_v1.1\MyAssembly.dll"
, it works just fine. When I call Get-Module
I see this imported assembly in the list:
ModuleType Version Name
---------- ------- ----
Binary 1.1.1.100 MyAssembly
Now the things start to get interesting. I import the other version of the assembly Import-Module "D:\another\path\to_v1.2\MyAssembly.dll"
. It again works just fine. So here're my questions:
Q1. Why are no errors shown? I expect to get an error: I'm trying to load an assembly with the same name but different version. I thought you could not load two different versions of the same assembly in one context. How are these situations handled, which loading contexts are used? Maybe the second version is not loaded at all?
Q2. Get-Module
now shows two modules with the same name and version, like this:
ModuleType Version Name
---------- ------- ----
Binary 1.1.1.100 MyAssembly
Binary 1.1.1.100 MyAssembly
It doesn't matter which version I import first. On the second Import-Module
the earliest imported version is duplicated in the Get-Module
list. I can only use the types/methods from the earliest imported version of the assembly as well.
Q3. My assembly has some dependencies on my other assemblies (in the same folder). These dependencies are automatically resolved and implicitly "imported" to the current session (I can use types from them no problem). Each version of the main MyAssembly.dll
depends on different versions of these secondary assemblies. When I import another version of MyAssembly
, I get no error about conflicting versions either. Once again, I can only use the types from the earliest imported secondary assemblies. I've read about "Dependency hell" and this should be impossible -- so how is that possible?
I've performed the same experiment with NuGet package Microsoft.CodeAnalysis.CSharp.dll
, versions 3.4.0
and 3.11.0
. The results are the same: versions and their dependencies are imported no problem, but only the earliest imported version is available.
Summary
When I import different versions of the same assemblies, I get no errors, but only the earliest imported versions are available. I want to understand why I'm able to load multiple versions of an assembly in one session without errors, how PowerShell handles these situations in general and why it shows two modules with the same versions, why I don't get dependency hell.
I want to understand what's going on, not just "make it work".
What am I missing here?
Thanks!