I have some code that gets the exception Unable to evaluate expression because the code is optimized or a native frame is on top of
the call stack. I have pasted some code below. I have confirmed that I am in mixed mode debugging, (native and managed). I have also confirmed that I am not 'pre-compiline' b4 debugging. the code is for a 'csv' download. Can someone help?
Response.Clear();
Response.ClearHeaders();
//set the conttent type of the file to be downloaded (IF NEEDED)
Response.ContentType =
"application/vnd.ms-excel";
// initialize the http content-disposition header to indicate a file attachment with the filename
Response.AppendHeader(
"Content-Disposition",
"Attachment; Filename=\"" + strFileNameCSV +
"\"");
//// transfer the file byte-by-byte to the response object
FileInfo fileToDownload =
new FileInfo(strFileNameCSV);
I'm not exactly sure of the intent of the error message but I got around the error by testing to see if the message contains the "Thread is being aborted" message. Here's an example:
I also face the same problem when i used Response.Redirect("url") within the try block. I have tryed many solution and finaly i decided to use response.Redirect("url") out of the try block.
So store the the url in a string variable(redirectUrl) in a try block and and write Response.Redirect out the try and catch block. Like
sorourke
Member
20 Points
4 Posts
Unable to evaluate expression because the code is optimized or a native frame is on top of the ca...
Apr 24, 2006 05:03 PM|LINK
Response.Clear();
Response.ClearHeaders();
//set the conttent type of the file to be downloaded (IF NEEDED)Response.ContentType =
"application/vnd.ms-excel"; // initialize the http content-disposition header to indicate a file attachment with the filenameResponse.AppendHeader(
"Content-Disposition", "Attachment; Filename=\"" + strFileNameCSV + "\""); //// transfer the file byte-by-byte to the response object FileInfo fileToDownload = new FileInfo(strFileNameCSV);Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Apr 24, 2006 08:11 PM|LINK
dexterm
Member
541 Points
148 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
May 04, 2006 03:18 PM|LINK
I'm not exactly sure of the intent of the error message but I got around the error by testing to see if the message contains the "Thread is being aborted" message. Here's an example:
if (ex.Message.StartsWith("Thread") == false)
{
Response.Redirect("~/Error.aspx?ErrorMsg = " + ex.Message);
}
HurdlerWorld@att.net
"Life isn't fair, sometimes the pretty girl doesn't get kissed..."
ShrinanD
Member
19 Points
3 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
May 04, 2006 06:10 PM|LINK
use Response.Redirect("~/Error.aspx?ErrorMsg = " + ex.Message,false);
ShrinanD vyas
vilindaT
Member
2 Points
3 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Jul 07, 2008 11:34 AM|LINK
Hi My friend
just put this code before of the final catch statement (Before Exception catch)
catch (System.Threading.ThreadAbortException lException){
// do nothing}
i think this will surview you from this error .
.Net 2.0 "asp.net 1.1" .cs "displayaing web page after complet loading" .net 3.0 .NET 2.0 Login Controls .ASPX .Net 2.0 navigation controls .ashx "asp.net 2.5" "visual studio" "custom control" toolbox dll unc "error loading types" .net 2.0 c#
lalit22
Member
2 Points
1 Post
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Jul 23, 2008 12:29 PM|LINK
.Net 2.0
arry.net
Member
624 Points
175 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Sep 05, 2008 01:08 PM|LINK
Thanks For the Solution It's Working Gr8 Thanks A lot Buddy
suthish nair
All-Star
15176 Points
3304 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Oct 27, 2008 11:53 AM|LINK
Also,
Please check this link reason and solution of the error: http://support.microsoft.com/kb/312629/EN-US/
Pradeep Kr. ...
Participant
1712 Points
294 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Feb 17, 2009 05:09 PM|LINK
Hi Friend,
I also face the same problem when i used Response.Redirect("url") within the try block. I have tryed many solution and finaly i decided to use response.Redirect("url") out of the try block.
So store the the url in a string variable(redirectUrl) in a try block and and write Response.Redirect out the try and catch block. Like
string rredirectUrl="";
try
{
//Code
redirectUrl="PaymentReceived.aspx";
}
catch(Exception ex)
{
redirectUrl="error.aspx"
}
Response.Redirect(redirectUrl);
Its Working in my application.
Sincerely,
Pradeep Kr. Sharma
Please remember to click “Mark as Answer” on the post that helps you.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://vshelpdesk.blogspot.com/
Please Mark As Answer, which helped you. So that it might be useful for others.
mehulkumarwa...
Member
348 Points
69 Posts
Re: Unable to evaluate expression because the code is optimized or a native frame is on top of th...
Sep 22, 2009 07:00 AM|LINK
Hi All,
the simple solution for this prblm is
use: Response.Redirect("URL_toRedirect",false);
it will work definately, i checked. (Y)
Development Engineer
"Please Mark AS Answer if it helps. Thanks"