Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare two AssemblyName instances?

Tags:

c#

.net

How do I compare two AssemblyName instances to figure out whether they represent the same assembly? The 'Equals' method isn't overriden.

One way I can think of is compare the 'ToString()' results of both the instances but I would prefer an 'Equals' syntax since I need to prepare a list (List) of 'unique' AssemblyName instances and would like to use the 'Contains(AssemblyName item)' method.

like image 470
alwayslearning Avatar asked Aug 11 '10 14:08

alwayslearning


1 Answers

As long as you are using strongly-named assemblies, comparing the output of the ToString method would be fine, as it outputs the full name of the assembly, which is supposed to be consistent and seems to be culture-invariant.

If the assemblies are not strong-named, then one can easily create another assembly with the same name and version number/culture and it would have the same assembly name as yours.

One thing to note though, because the assembly names are the same doesn't mean that the assemblies are the same physical identity; location is not part of the assembly name.

like image 95
casperOne Avatar answered Oct 02 '22 04:10

casperOne