Tuesday, November 22, 2016

NetTiers Ambiguous match found

I recently ran into a bug that took me longer than it should have to figure out.

I was migrating an old code base to CodeSmith's NetTiers and started getting the error "Ambiguous match found".  Results from the Internet all pointed the finger at Microsoft's .net, albeit earlier versions than version 4.5 that I was using.

While I did become convinced that it was a Microsoft issue relating to two object attributes with the same name just different letter casing, that did not solve my issue for me because my code was all being auto generated by NetTiers.  NetTiers was using reflection to get some attribute values, so I figured one of my table or column names was conflicting with some internal variable that NetTiers was using.

The solution turned out to be rather simple.  I ran the code in debug mode, triggered the crash, and started inspecting the variables in play.  Particularly the one NetTiers was trying to find using reflection.  It turned out that NetTiers was looking for an attribute named "Item", which corresponded to a table column of the same name, and was blowing up in the attempt.  I renamed that column in my database, regenerated the code, and the problem was solved.