Green Dragon's Lair

Ambiguous Match Found exception and a recursive function

I've had the wildest goose chase this thursday hunting down a bug...

I'm using ActiveRecord, and was calling ActiveRecordStarter.Initialize, when I started getting an AmbiguousMatchFound from ActiveRecord. From the little that there was out there on this exception, it was supposed to be because of two classes having the same name and the runtime wasn't able to distinguish between them, which is wierd in itself, as the compiler shouldn't allow something like that to compile in the first place.

I've tried stuff like getting all the types in all the assemblies in the current appdomain to see if maybe I did had duplicate class names by mistake, but the only duplicates were from generic anonymous delegates and they were defined as internal classes in any case.

I've spent the entire day trying to figure out what changed, luckily I'm working with Vault, so I pulled yesterday's daily build by CruiseControl.Net, and it didn't exhibit the problem, so I knew it had to be something I did today.

The only real change I've done today was add new two ActiveRecord classes, so I took a closer look at them.

One of the classes was a CompositeKey for the other one, and when you have a composite key class in ActiveRecord, you must implement Equals and GetHashCode so the reference equality tests could check the key values rather than just the reference itself.

I noticed that the Equals function was indicated as recursive by Resharper (which implemented it for me in the first place), and that seemed odd to me... Resharper creates one overriding function with an object parameter and one function with the type of the key that is called from the overriding function after testing that the object passed is indeed of that type.

For some reason, the specific type function was missing, and therefore the general object function was calling itself. I don't know what it caused inside ActiveRecord, but my guess is that during initialization, ActiveRecord uses the Equals function in some way, and that recursive call got it confused.

Once I've added the specific type function, everything was back to normal... after almost 8 hours of hair tearing...


Posted Jul 06 2007, 12:34 PM by admin

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
(C) Miki Watts
Powered by Community Server (Non-Commercial Edition), by Telligent Systems