windows 获取错误 错误:字典中不存在给定的键。生产中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12732213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:54:00  来源:igfitidea点击:

Getting error Error: The given key was not present in the dictionary. in production

c#asp.netwindowsweb-servicesiis

提问by Sugitime

I am using ASP.Net 4.0 w/ a C# Web service. This also utilizes a C# library, which is working fine in development and with other applications (Skype bot and Windows form)

我正在使用带有 C# Web 服务的 ASP.Net 4.0。这也利用了一个 C# 库,该库在开发和其他应用程序(Skype 机器人和 Windows 表单)中运行良好

I am using JQuery to communicate via JSON to the web service. In development, this is working fine. In production, it is partly working. I can use some commands, but other commands simply throw this error:

我正在使用 JQuery 通过 JSON 与 Web 服务进行通信。在开发中,这工作正常。在生产中,它部分工作。我可以使用一些命令,但其他命令只会抛出此错误:

Error: The given key was not present in the dictionary.

I am not certain where to begin with this. I can't step through code because it only happens in prod. I checked the IIS logs, and every request is getting a 200 status, so it appears it is something inside of the app itself. Any ideas where to start with this?

我不确定从哪里开始。我无法单步执行代码,因为它只发生在 prod 中。我检查了 IIS 日志,每个请求都处于 200 状态,因此它似乎是应用程序本身的内部内容。任何想法从哪里开始?

采纳答案by Sugitime

The issue was that I was using WebClient to call a URL that required a Login. I setup my app pool w/ my domain creds and then I was able to call the page w/o being prompted for a login.

问题是我使用 WebClient 调用需要登录的 URL。我使用我的域凭据设置了我的应用程序池,然后我能够在没有提示登录的情况下调用该页面。

Once calling the page, I was able to populate a list and loop through it. The error above was thrown because I was looping through an empty list.

一旦调用该页面,我就能够填充一个列表并循环遍历它。抛出上面的错误是因为我正在遍历一个空列表。

回答by Eric J.

The error suggests that the server-side code is attempting to access a dictionary with a key that is not in that dictionary.

该错误表明服务器端代码正在尝试使用不在该字典中的键访问字典。

I suggest modifying the code to place error handling around all dictionary access. When handling the error, log the key that was attempted to be read from the dictionary.

我建议修改代码以在所有字典访问周围放置错误处理。处理错误时,记录试图从字典中读取的键。

When logging exception details, it is wise to log all available information.

记录异常详细信息时,最好记录所有可用信息。

Exception.ToString()

accomplishes just that.

做到了这一点。

回答by user4519391

You can delete all queue message from sqlsrver Queue you are using as ,

您可以从正在使用的 sqlsrver 队列中删除所有队列消息,

declare @c uniqueidentifier
while(1=1)
begin
    select top 1 @c = conversation_handle from dbo.yourqueuenqme
    if (@@ROWCOUNT = 0)
    break
    end conversation @c with cleanup
end

It will work after that .

在那之后它会起作用。