Search code examples
.netclrmetadata.net-assemblystrongname

Strong Named Assembly And Public Key Token


Consider a situation when two public keys of two different publishers’ assemblies are mapped to the same public key token (while name, version and culture of the assemblies are also the same).

When the CLR will try to resolve an AssemblyRef entry that intended to reference only one of the above, will it be able to know exactly which one should be loaded?
I’m sure nothing is left for luck, so how will it work?
Maybe it's a tradeoff, having shorter keys, saving space with the risk of collisions?

source: CLR via C#, 4th edition, page 71 (head).


Solution

  • There is no ambiguity when the assembly is stored in the GAC, one assembly will replace the other. So you'll get whichever was registered last.

    When it is not stored in the GAC then the CLR will only ever locate an assembly based on the display name. It searches through the directories in the probing path for a file whose filename matches the display name with a file extension of .exe or .dll. First one it finds completes the search, kaboom if the rest of the AssemblyName doesn't match. You'll have a hard time storing an assembly with the same display name in the same directory, but it is technically possible to have one named .exe and the other named .dll. The .exe is found first.

    This is all rather well documented in this MSDN Library article.