.net mscorlib.dll 中发生了“System.Threading.ThreadAbortException”类型的第一次机会异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1973149/
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-03 13:42:56  来源:igfitidea点击:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

.net

提问by kaushalparik27

I am working on an asp.net application.. when I try to compile and run the application; it runs successfully.

我正在开发一个 asp.net 应用程序……当我尝试编译和运行该应用程序时;它运行成功。

But when I try to debug the application it gives me error at any point -

但是当我尝试调试应用程序时,它在任何时候都会给我错误 -

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

mscorlib.dll 中发生了“System.Threading.ThreadAbortException”类型的第一次机会异常

It doesnt give error at any specific code line.. it gives this error at any code of line (not sure).. and then web page display - "Server Application Unavailable" error.

它不会在任何特定代码行出现错误..它在任何行代码(不确定)处给出这个错误..然后网页显示 - “服务器应用程序不可用”错误。

Even when I try to parse/execute some statement in immediate window / quick watch - it gives me above error..

即使我尝试在即时窗口/快速监视中解析/执行某些语句 - 它也给了我上述错误..

for example, I loaded an xml document (of more than 10000 lines) in XElement and when I try to check some attribute value thru xpath as XElementObj.XPathSelectElement("/asdf/asd/wqer/xyz").. it gives above error.. (not all the time but randomly).

例如,我在 XElement 中加载了一个 xml 文档(超过 10000 行),当我尝试通过 xpath 检查某些属性值作为 XElementObj.XPathSelectElement("/asdf/asd/wqer/xyz").. 它给出了上述错误..(不是一直都是随机的)。

anybody having any idea on this.. please help.

任何对此有任何想法的人..请帮忙。

回答by Christian Payne

I had something similar, and found this answerfrom another question:

我有类似的东西,并从另一个问题中找到了这个答案

If you want to pinpoint where the exceptions are occurring, you can select the Debug->Exceptions menu item, and in the dialog that appears, check the first checkbox for "Common Language Runtime Exceptions". This will make the debugger break as soon as an exception occurs instead of only breaking on unhandled exceptions.

This is also one reason why it is generally a bad idea to catch generic exceptions unless you are clearly logging the information caught.

如果要查明异常发生的位置,可以选择 Debug->Exceptions 菜单项,然后在出现的对话框中,选中“Common Language Runtime Exceptions”的第一个复选框。这将使调试器在异常发生时立即中断,而不是仅在未处理的异常时中断。

这也是为什么除非您清楚地记录捕获的信息,否则捕获通用异常通常是一个坏主意的原因之一。

回答by Hulvej

I had this exception thrown in my asp.net app, and found this forum post:

我在我的 asp.net 应用程序中抛出了这个异常,并找到了这个论坛帖子

PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer http://support.microsoft.com/default.aspx?scid=kb;en-us;312629

PRB:如果您使用 Response.End、Response.Redirect 或 Server.Transfer,则会发生 ThreadAbortException http://support.microsoft.com/default.aspx?scid=kb;en-us;312629

This make sense as I was redirecting on a page right before anything was rendered (expected behavior by the way)

这是有道理的,因为我在呈现任何内容之前就在页面上重定向(顺便说一下,预期的行为)

Workaround by MS to suppress any exceptions:

MS 抑制任何异常的解决方法:

To work around this problem, use one of the following methods:

要解决此问题,请使用以下方法之一:

  • For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.

  • For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example: Response.Redirect ("nextpage.aspx", false);

  • For Server.Transfer, use the Server.Execute method instead.

  • 对于 Response.End,调用 HttpContext.Current.ApplicationInstance.CompleteRequest 方法而不是 Response.End 将代码执行绕过到 Application_EndRequest 事件。

  • 对于 Response.Redirect,使用重载 Response.Redirect(String url, bool endResponse) 为 endResponse 参数传递 false 以抑制对 Response.End 的内部调用。例如:Response.Redirect ("nextpage.aspx", false);

  • 对于 Server.Transfer,请改用 Server.Execute 方法。

If you use this workaround, the code that follows Response.Redirect is executed. For Server.Transfer, use the Server.Execute method instead.

如果您使用此解决方法,则将执行 Response.Redirect 后面的代码。对于 Server.Transfer,请改用 Server.Execute 方法。