tags:

views:

903

answers:

2

I have a set of websites built in MVC - each, essentially, is a clone of one original site). On one of the sites I'm getting the error from the title of this post ("The given key was not present in the dictionary") - it only occurs on a single page. The code is identical across all of the sites including the one which is acting up. Each of the sites is installed with the same setup (most of them are parallel to each other on a single server). I'm unable to replicate this in my Dev environment so have no idea how to debug (our sites are compiled via a Nant build process and are all set to Release mode - so no debug info available).

When I look into the stack trace of the error I notice that at no point does our code get called - it's all ASP.Net page-lifecycle calls (specifically, the last significant function is a method called "__RenderSearchContent" in the compiled page. So far as I can tell from digging through the relevant controller action there are no instances where the code is using a Dictionary object.

It seems to me that I'm missing something but I'm not sure where to look - the code doesn't seem to be the problem, there shouldn't be any environmental differences (though, it isn't impossible - the database, for example, is a different install but has an identical schema and isn't being used yet according to the stack trace).

One area I have suspicion of is the routing which I know uses a dictionary - but surely, if this was the case, the other sites would suffer from the same problem?

Are there any suggestions as to where I might look to find the cause of this problem?

Any help will be much appreciated.

Cheers

+1  A: 

Check whether the query (or form) parameters for the request that causes the problem contain a parameter (or parameters) corresponding to the names of the controller action's arguments. When the action is invoked, it should look in the parameters of the request for named parameters matching the names of the action's arguments.

tvanfosson
Hi, thanks for the answer. It was a good suggestion to check the route parameters but, in this case, not the solution. I describe the solution in the answer I've provided.
Zac
+2  A: 

Ok, so the problem was not where I was expecting it to be. If I had a dollar for every time that happened...

Basically, the problem was located in the view that was throwing the error. There was a data item which was present in the other websites but not this one. I guess this type of problem is where strongly-typed objects are ideal.

Zac