tags:

views:

40

answers:

2

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.

A: 

I would compare the AssemblyName.FullName property, as it represents the actual version specific identity of the assembly.

Matthew Abbott
`AssemblyName.ToString` is overridden to return the same thing as `AssemblyName.FullName`
ho1
+2  A: 

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.

casperOne
This may not prove adequate if the assemblies are not strong named. I'm pretty sure without strong naming, it's possible to make two assemblies appear to have the same name yet actually be completely different inside.
Matt Greer
@Matt : In my case I can safely assume that I am dealing with strongly named assemblies.
alwayslearning
@Matt Greer: Updated answer to reflect comments.
casperOne