Tuesday, March 13, 2012

System.Threading.ThreadAbortException

Hi,

I'm running some code that posts from my application (ASP.Net) to a Payment Gateway. I get this error - [System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}. I guess this is because my I am transfering to another server and once this is done my code doesn't know what to do with itself.

Could someone explain what this error is precisely, and how I might avoid it.

Regards,

Quinton Smith

For any one wondering what I did to get this working as no one answered, I had to move my code transferring so that it was the last code running before transfer and not in any try/catch blocks.

Still don't quite understand the error description though.

Quinton


Not enough info to give an accurate answer, but if you're using Response.Redirect:

From Visual Studio Help:
Redirect calls End which always raises a ThreadAbortException exception upon completion.

NC...


youre the man! out of the first couple of posts yours is the only one that actually helped KUDOS!

Hi Programmers,

I am using asp.net 2.0 with c#.

" myReportDocument.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, false, rptName);"

As soon as compiler execute this statement i get error

" [System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.} "

What will be the possible reasons for the error.

Sorry for the bad english.


I believe that this is because, Response.End is called internally in the ExportToHttpResponse method:

Try wrapping it in a try/catch block:

try
{
myReportDocument.ExportToHttpResponse(...);
}
catch (System.Threading.ThreadAbortException)
{
}

NC...


Thanks for reply,

I m already using try{} catch{} block

try

{

Some coding here

try
{

Response.TransmitFile("CodeGeneratedFiles/" + TemplateFileName);
Response.End();
}

catch (System.Threading.ThreadAbortException ex)
{
Log.WriteLog("Report Viewer", "Set The Datasource", ex.Source, ex.Message);
}

Response.Addheader("Title","Some Name for Popup");

}

Catch(Exception ex)

{

}

But it does not execute "Response.Addheader("title","Some Name for Popup");" after catch block it directly jumps to outer catch block.

Is there anyway to kill the exception..

Is there no other way to solve this error.[System.Threading.ThreadAbortException] = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

Hope to hear u soon.


No as I think there is a bug in ExportToHttpResponse. You might try Googling ExportToHttpResponse and System.Threading.ThreadAbortException. I found some work-a-rounds there.

NC...

0 comments:

Post a Comment