ASP.Net MVC:“给定的密钥在字典中不存在" [英] ASP.Net MVC: "The given key was not present in the dictionary"

查看:70
本文介绍了ASP.Net MVC:“给定的密钥在字典中不存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组用MVC构建的网站-每个网站本质上都是一个原始网站的克隆).在其中一个网站上,我从此帖子的标题中得到了错误(字典中不存在给定的键")-它仅出现在单个页面上.该代码在所有站点(包括正在运行的站点)上都是相同的.每个站点都使用相同的设置进行安装(大多数站点在单个服务器上彼此平行).我无法在开发环境中复制它,所以不知道如何调试(我们的站点是通过Nant构建过程进行编译的,并且都设置为发布"模式-因此没有可用的调试信息).

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).

当我查看错误的堆栈跟踪时,我注意到我们的代码没有被调用-这就是所有ASP.Net页面生命周期调用(具体来说,最后一个重要的函数是方法中的"__RenderSearchContent"方法)据我从挖掘相关的控制器操作所知,没有任何实例在其中代码在使用Dictionary对象.

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?

任何帮助将不胜感激.

欢呼

推荐答案

好,所以问题不在我期望的位置.如果我每发生一次 都拥有一美元,那么...

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.

这篇关于ASP.Net MVC:“给定的密钥在字典中不存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆