Sunday, August 22, 2010

Reflector gotcha: Identical class names

@YaronNaveh

Some time ago I inspected WSE2's MessageSignature.CreateTransform method in the reflector.

Here is a snippet from it:



if (transform is XmlDsigXPathTransform)

{

   
return new XmlDsigXPathTransform();

}

It seemed what I was looking for at the moment so I pasted it into my project. Immediatelly ReSharper suggested me to add a using to "Microsoft.Web.Services2.Security". I hoped to save a few coding seconds so I accepted the offer.

A few hours later I have encountered some strange behavior at runtime which forced me to check this code again. It looked identical to the WSE2 code from the reflector so I assumed it should work. It still looked identical in the second and third times I checked but then... I hovered over the first XmlDsigXPathTransform in the reflector and saw it was from the "System.Security.Cryptography.Xml" namespace! It turned out that the code used two classes with the same name but from different namespaces. Seems like the reflector will not add the full namespace even in case of ambiguity.

Keep that in mind next time you copy WSE2 code to your projects :)

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

0 comments: