ASP.NET MVC 2 - An item with the same key has already been added.

I was working with asp.net mvc, and all of a sudden, on a form post I kept getting :

An item with the same key has already been added.

My model looked ok, the data being submited looked ok - I just couldn't figure it out. I wanted to debug into the MVC2 source (started to think select was broken :) ) ... which lead me down a path where I eventually reinstalled VS 2010 :) .

Eventually I came to my senses and started to think about it. I realized that my view Model had a base class - and then it hit me : in the base class I had a property "UserName" and in the child class "Username". Notice the small difference in caseing. 

Since the model binder doesn't care about case - there you have it : a nice cryptic error. 

Hth.

Tags: