Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack


:P
On this page:

All of a sudden I’m getting this error message in my inbound Web Service that’s been working fine for several days:

 

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

 

The Web Service just started failing all of a sudden, and I’ve been trying to back track what’s changed, but I can’t find anything wrong here.

 

The behavior that I’m seeing is mighty whacky: If I run in the debugger the code will throw this exception on random spots in the Web Service method. The code comes in and the inbound object parameter looks fine and the lines of code that bonking are lines that should not be failing like straight assignments of values that the debugger shows as valid.

 

Even weirder at some point, things were working for a few minutes again with requests going through and the debugger going through the whole code, but then it went right back to failing again.

 

I can’t figure out what is different as there were no code changes between these episodes when it didn't work, then worked then not... I recompiled, I stopped IIS deleted all assemblies to ensure there are no version conflicts prior to rebooting. None of this seemed to have any effect...

 

Finally I rebooted the machine and now things are working correctly again, but I really can’t make any sense of this…

 

Anybody have any idea? I’ve searched around a bit and this error seems common, but I didn’t find a solution in any of the posts I read – most of the issues are related to straight ASP.NET and Response.Redirect related issues apparently. This is not the case here since this is a Web Service and there’s no interaction with any of the ASP.NET objects.

 

Is it possible that the .NET Runtime Optimization Service is doing something behind the scenes here that it shouldn't be? I'm just checking my settings now and it looks like this service is off now, but i didn't check while the failure was happening.

 

This sort of thing is worrisome – I hate it when you run into a problem and the answer is: Reboot the system. <g>…


The Voices of Reason


 

Steve from Pleasant Hill
August 10, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I dislike it too, but unfortunately a reboot seems to solve the odd esoteric problem that creeps in during the debug and fix cycle.

Doug Dodge
August 10, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Rick,

I'm sure you've done this but I googled "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack" and got a couple of interesting hits.

best,

DD

Rick Strahl
August 10, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Steve - I haven't seen anything else that is severe and odd enough to require a reboot. I'm just wondering what in a .NET application - a web app even - would stick around through an IIS restart... It bugs me to think that there's no explanation <s>...

Doug, yes I searched for it for a while - came up with lots of hit with a wide variety of different scenarios none of which seemed to point at a useful solution.

# DotNetSlackers: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack


Raj
November 02, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Rick,

I have the same issue. Restart doesnt seem to work for me.. I googled but found nothin..

- Raj

Dave
November 04, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Best analysis of this type of problem is at

http://blogs.msdn.com/jmstall/archive/2005/11/15/funceval-rules.aspx

Note : analysis not solution

shakeel khan
December 10, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Hi,
I am getting same problem with "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
And always occurs even if there is no error
I used finally block and initialize bool variable in catch block and used in finally block.
Have a look code

try
{
Response.Redirect(Request.Path + "?result=submitted");

// if you using Response.Redirect or Server.Transfer in Try block you will get these error
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." It’s .Net bugs.

}

catch
{
this._response = false;
// Response.Redirect(Request.Path + "?result=error");
}
finally
{
if(_response)
Response.Redirect(Request.Path + "?result=submitted");
else
Response.Redirect(Request.Path + "?result=error");
}

srinivas
December 18, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

by removing try catch it is working fine. check it.

srinivas
December 18, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

use Response.Redirect ("nextpage.aspx", false);
for server.Transfer use Server.Execute method instead.

http://support.microsoft.com/kb/312629/EN-US/

guyfromny
December 28, 2006

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Rick,

I am having this exactly same problem when I try to call a web service (in a try-catch block). Even I tried looking for a solution but most of them are with Response.Redirect. Did you find any solution for your problem. If yes, I wud appreciate if you can share it.

manjula
February 22, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Iam also getting the same error where Iam using Response.redirect in try - catch block.

tried all the options mentioned above.But still getting the same error.please let me know if there is any other solution.

mahesh
March 13, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

thanks for help. really a good one which solved the problem

Spencer
March 14, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Adding the ...", false)" fixed the problem!

Thank you!

Rajesh Amaladoss
May 18, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I am also facing the same problem but after adding false in Response.redirect stmt executed
sucessfully.

Nick Lucas
June 04, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I had the same problem last week when trying to access a web service from an XBAP page. This was when the call was in progress and I'd set a breakpoint on it. On trying to examine the text of a textbox the above message was shown against all of the textbox properties. Double checking this today I found that the IP address that the web service was using to access the SQL database was set to the live database instead of my local copy. The live database could only be accessed when a VPN connection was up and running. I had no VPN connection so the web service was unable to connect and eventually times out. After the timeout had occured the textbox properties were shown correctly. If I change the call to the web service to be the async method then the properties of the textbox are correct. So I'm reading this as a "I can't show you this right now as I'm busy doing something else", quite a lot of Microsoft messages don't really explain in detail what they actually mean IMHO.

Krishanvir singh solanki
September 22, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

My problem solved by using
Response.Redirect ("nextpage.aspx", false);

Himanshu
October 23, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Ya, This will solve my problem too, thanz a lot

neha
October 24, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

hey neither puuting true false as second parameter nd niether putting it outside try block is working for me....pllzzz help.....i am redirecting to an login page...if i sppend wrong username and passwrd to url then i get failure nd response .redirect is working fine...but if i give right values then it gives exception..how ca dis happen?????ny idea

Sandesh
October 29, 2007

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Thanks... Adding false to the Response.Redirect ("page.aspx",false) worked for me.

Mahesh
February 26, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Adding False parameter in Response.Redirect works fine for me. Thanks a lot

Gary B
March 27, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

This seems to be related to the ~ character in the response.redirect for me.

What I was doing was a redirect to a page like ~/login.aspx?url={path}. If I choose the EndRequest = false when doing the response.redirect then the error doesn't occur, but the url={path} doesn't appear.

In the end I got rid of the try and catch block to get it to work properly. Fortunately theres not much that can go wrong in that section of code.

pranjal
April 15, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I don't get proper solution for the same error.
plz help me .

shaby
June 16, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Hi, u r correect because i am receiving the same error in my webapplication but i do not think it is response.redirect as i did remove try and catch to resolve this issue but it does not work. then i try to put response.redirect to finally block then also it did not work. I also used Reponse.Redirect(string url,bool false) then also it did not work. I put set the debug mode as mixed mode that native and managed both but nothing seems to work.

uzhiel
June 19, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Thanks for the tip regarding Response.Redirect.. and thanks Nick for making this problem open on your forum.

One thing I am still unsure about is why the errors stopped appearing after rebooting IIS. It just sounded random.

korhan
July 08, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

thanks a lot
false parameter solved the problem

Paolo
July 25, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

it worked also for me, "false" param avoided the exception but.... the redirect does not occur! any idea? the code is in a page which is a popup from a nother page..but this shoudn't be a problem....

reshma
July 31, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

can anyone please say why we are putting that false or true after response.redirect what is the use of that... please let me know because without knowing we cannot code..

Rajeev
August 13, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Thanks, I get rid from this error, adding Response.Redirect("YourFileName.aspx", false). Its working fine. Thanks a lot

sk
August 20, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

it has nothing to do with Response.Redirect or Try catch blocks as some have mentioned.

I ran into the same problem when i tried to use Unit tests generated by Visual studio 2008.
When I used a console application instead of test project to test the functionality the error did not occur.

I guess the problem is due to the way debugging happens and probably debugger was not able to evaluate the expression and thereby throwing the error.

srikanth
September 01, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

iam facing above problem when adding privileges to employee.in catch block iam getting this error.but iam getting result but not perfect.

Vijay
November 05, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I too get same error when execute Response.End();
What will be solution for this?

-Vijay

Ben
November 26, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Adding the "false" at the end solved the problem.
Response.Redirect("webpage.aspx?param=" + test.Id, false);

Art
November 29, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

hi,

im not using asp.net, but i may contribute some information, that help you understand the problem.

from my knowledge this problem is a threading issue. i am implementing a heavily multithreaded application and at some point i also got this exception:

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

in my case the cause for this exception was, that a thread called Abort() on its own thread-object representation (like MyThread.Abort();). this call happened in a try-catch-block, but the exception was raised elsewhere. it was raised in the method the thread was originally created with (this might be the reason why i read in forums that an "uncatchable" exception is raised - it seems it is just raised where programmes do not expect it). i have a catch there too (allthough i expected a "ThreadAbortException"), so i have been able to figure out this problem.

to look at this problem as a threading issue, may also explain the unreproducable exceptions, as with threads race conditions can occure.

in my case i had to make sure the thread cannot enter code where functions on its own object-representation are called. in my case it was the dispose method of an object that contains the object in which the thread originally was created. the thread got there by a raised event, that would cause the program to end and therefore dispose all disposable objects, including calling dispose on the object the thread was created in. in this dispose-method i implemented the Thread.Abort(), not forseeing this very same thread one day would come home trying to kill itself :-)

hope this helps,
art

YO
December 04, 2008

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

You can mark up code snippets with:
your code
.
Supported lare: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by YO
re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Vijay November 05, 2008 @ 4:14 am
application - a web app even - would stick around through an IIS restart... It bugs me to think that there's no explanation <s>...

Doug, yes I searched for it for a while - came up with lots of hit with a wide variety of different scenarios none of which seemed to point at a useful solution.



DotNetSlackers: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by DotNetSlackers Latest ASP.NET News October 09, 2006 @ 1:30 am

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Raj November 02, 2006 @ 11:22 pm

Rick,

I have the same issue. Restart doesnt seem to work for me.. I googled but found nothin..

- Raj

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Dave November 04, 2006 @ 3:09 am

Best analysis of this type of problem is at

http://blogs.msdn.com/jmstall/archive/2005/11/15/funceval-rules.aspx

Note : analysis not solution

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by shakeel khan December 10, 2006 @ 4:59 pm

Hi,
I am getting same problem with "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."
And always occurs even if there is no error
I used finally block and initialize bool variable in catch block and used in finally block.
Have a look code

try
{
Response.Redirect(Request.Path + "?result=submitted");

// if you using Response.Redirect or Server.Transfer in Try block you will get these error
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." It’s .Net bugs.

}

catch
{
this._response = false;
// Response.Redirect(Request.Path + "?result=error");
}
finally
{
if(_response)
Response.Redirect(Request.Path + "?result=submitted");
else
Response.Redirect(Request.Path + "?result=error");
}

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by srinivas December 18, 2006 @ 12:26 am

by removing try catch it is working fine. check it.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by srinivas December 18, 2006 @ 12:33 am

use Response.Redirect ("nextpage.aspx", false);
for server.Transfer use Server.Execute method instead.

http://support.microsoft.com/kb/312629/EN-US/

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by guyfromny December 28, 2006 @ 11:34 am

Rick,

I am having this exactly same problem when I try to call a web service (in a try-catch block). Even I tried looking for a solution but most of them are with Response.Redirect. Did you find any solution for your problem. If yes, I wud appreciate if you can share it.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by manjula February 22, 2007 @ 11:55 pm

Iam also getting the same error where Iam using Response.redirect in try - catch block.

tried all the options mentioned above.But still getting the same error.please let me know if there is any other solution.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by mahesh March 13, 2007 @ 2:37 am

thanks for help. really a good one which solved the problem

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Spencer March 14, 2007 @ 11:41 am

Adding the ...", false)" fixed the problem!

Thank you!

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Rajesh Amaladoss May 18, 2007 @ 9:52 pm

I am also facing the same problem but after adding false in Response.redirect stmt executed
sucessfully.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Nick Lucas June 04, 2007 @ 1:26 am

I had the same problem last week when trying to access a web service from an XBAP page. This was when the call was in progress and I'd set a breakpoint on it. On trying to examine the text of a textbox the above message was shown against all of the textbox properties. Double checking this today I found that the IP address that the web service was using to access the SQL database was set to the live database instead of my local copy. The live database could only be accessed when a VPN connection was up and running. I had no VPN connection so the web service was unable to connect and eventually times out. After the timeout had occured the textbox properties were shown correctly. If I change the call to the web service to be the async method then the properties of the textbox are correct. So I'm reading this as a "I can't show you this right now as I'm busy doing something else", quite a lot of Microsoft messages don't really explain in detail what they actually mean IMHO.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Krishanvir singh solanki September 22, 2007 @ 3:44 am

My problem solved by using
Response.Redirect ("nextpage.aspx", false);

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Himanshu October 23, 2007 @ 3:17 am

Ya, This will solve my problem too, thanz a lot

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by neha October 24, 2007 @ 10:45 pm

hey neither puuting true false as second parameter nd niether putting it outside try block is working for me....pllzzz help.....i am redirecting to an login page...if i sppend wrong username and passwrd to url then i get failure nd response .redirect is working fine...but if i give right values then it gives exception..how ca dis happen?????ny idea

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Sandesh October 29, 2007 @ 3:39 am

Thanks... Adding false to the Response.Redirect ("page.aspx",false) worked for me.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Mahesh February 26, 2008 @ 1:07 am

Adding False parameter in Response.Redirect works fine for me. Thanks a lot

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Gary B March 27, 2008 @ 3:33 am

This seems to be related to the ~ character in the response.redirect for me.

What I was doing was a redirect to a page like ~/login.aspx?url={path}. If I choose the EndRequest = false when doing the response.redirect then the error doesn't occur, but the url={path} doesn't appear.

In the end I got rid of the try and catch block to get it to work properly. Fortunately theres not much that can go wrong in that section of code.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by pranjal April 15, 2008 @ 11:57 pm

I don't get proper solution for the same error.
plz help me .

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by shaby June 16, 2008 @ 5:23 am

Hi, u r correect because i am receiving the same error in my webapplication but i do not think it is response.redirect as i did remove try and catch to resolve this issue but it does not work. then i try to put response.redirect to finally block then also it did not work. I also used Reponse.Redirect(string url,bool false) then also it did not work. I put set the debug mode as mixed mode that native and managed both but nothing seems to work.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by uzhiel June 19, 2008 @ 11:48 pm

Thanks for the tip regarding Response.Redirect.. and thanks Nick for making this problem open on your forum.

One thing I am still unsure about is why the errors stopped appearing after rebooting IIS. It just sounded random.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by korhan July 08, 2008 @ 8:56 am

thanks a lot
false parameter solved the problem

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Paolo July 25, 2008 @ 8:43 am

it worked also for me, "false" param avoided the exception but.... the redirect does not occur! any idea? the code is in a page which is a popup from a nother page..but this shoudn't be a problem....

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by reshma July 31, 2008 @ 6:39 am

can anyone please say why we are putting that false or true after response.redirect what is the use of that... please let me know because without knowing we cannot code..

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Rajeev August 13, 2008 @ 12:56 am

Thanks, I get rid from this error, adding Response.Redirect("YourFileName.aspx", false). Its working fine. Thanks a lot

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by sk August 20, 2008 @ 10:21 am

it has nothing to do with Response.Redirect or Try catch blocks as some have mentioned.

I ran into the same problem when i tried to use Unit tests generated by Visual studio 2008.
When I used a console application instead of test project to test the functionality the error did not occur.

I guess the problem is due to the way debugging happens and probably debugger was not able to evaluate the expression and thereby throwing the error.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by srikanth September 01, 2008 @ 11:25 pm

iam facing above problem when adding privileges to employee.in catch block iam getting this error.but iam getting result but not perfect.

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Vijay November 05, 2008 @ 4:14 am

I too get same error when execute Response.End();
What will be solution for this?

-Vijay

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Ben November 26, 2008 @ 8:49 am

Adding the "false" at the end solved the problem.
Response.Redirect("webpage.aspx?param=" + test.Id, false);

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Art Saturday @ 5:38 am

hi,

im not using asp.net, but i may contribute some information, that help you understand the problem.

from my knowledge this problem is a threading issue. i am implementing a heavily multithreaded application and at some point i also got this exception:

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

in my case the cause for this exception was, that a thread called Abort() on its own thread-object representation (like MyThread.Abort();). this call happened in a try-catch-block, but the exception was raised elsewhere. it was raised in the method the thread was originally created with (this might be the reason why i read in forums that an "uncatchable" exception is raised - it seems it is just raised where programmes do not expect it). i have a catch there too (allthough i expected a "ThreadAbortException"), so i have been able to figure out this problem.

to look at this problem as a threading issue, may also explain the unreproducable exceptions, as with threads race conditions can occure.

in my case i had to make sure the thread cannot enter code where functions on its own object-representation are called. in my case it was the dispose method of an object that contains the object in which the thread originally was created. the thread got there by a raised event, that would cause the program to end and therefore dispose all disposable objects, including calling dispose on the object the thread was created in. in this dispose-method i implemented the Thread.Abort(), not forseeing this very same thread one day would come home trying to kill itself :-)

hope this helps,
art


I too get same error when execute Response.End();
What will be solution for this?

-Vijay

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Ben November 26, 2008 @ 8:49 am

Adding the "false" at the end solved the problem.
Response.Redirect("webpage.aspx?param=" + test.Id, false);

re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
by Art Saturday @ 5:38 am

hi,

im not using asp.net, but i may contribute some information, that help you understand the problem.

from my knowledge this problem is a threading issue. i am implementing a heavily multithreaded application and at some point i also got this exception:

"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

in my case the cause for this exception was, that a thread called Abort() on its own thread-object representation (like MyThread.Abort();). this call happened in a try-catch-block, but the exception was raised elsewhere. it was raised in the method the thread was originally created with (this might be the reason why i read in forums that an "uncatchable" exception is raised - it seems it is just raised where programmes do not expect it). i have a catch there too (allthough i expected a "ThreadAbortException"), so i have been able to figure out this problem.

to look at this problem as a threading issue, may also explain the unreproducable exceptions, as with threads race conditions can occure.

in my case i had to make sure the thread cannot enter code where functions on its own object-representation are called. in my case it was the dispose method of an object that contains the object in which the thread originally was created. the thread got there by a raised event, that would cause the program to end and therefore dispose all disposable objects, including calling dispose on the object the thread was created in. in this dispose-method i implemented the Thread.Abort(), not forseeing this very same thread one day would come home trying to kill itself :-)

hope this helps,

You can mark up code snippets with:
your code.
Supported languages are:
nguages are:

DotNetGuts
January 11, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

For Solution of Error: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

http://dotnetguts.blogspot.com/2009/01/unable-to-evaluate-expression-because.html

Siju Ganapathy
January 15, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I select C#.Net as backend language here,

If we consider the back button in a page , we would get get previous address by the property
Request.UrlReferrer.AbsoluteUri; the returning string contains whole dynamic address
in which you have to pickup the page.aspx.That is possible for you.
Applay it in server.Transfer(page.aspx);

Remaind server.Transfere(page.aspx);
not enough you have to set session["Title"] too.

Arun
April 26, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

hi,

In abc.aspx web page

I use response.redirect("xyz.aspx",false);

It opens xyz.aspx page in a new window.

But the code present after the response.redirect in abc.aspx web page is not working.

Pls give solution

Nicolas
June 10, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

you can't call the same page with "redirect", you just need to call you function...

Clay Lenhart
July 01, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Thanks! I had the same problem (NOT related to Response.Redirect()).

The solution (for me):

My program was multithreaded and the main thread was finishing before the sub threads. In my code, the main thread waits a few seconds for child threads to finish and then starts calling Thread.Abort() on the child threads. The exception raised in the child thread was caused by Thread.Abort(), not due to some of the web service calls they were making.

varun
July 13, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Thanks, adding "false" to response.redirect solved my problem.

Ajay
July 24, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I am getting da same problem, but am getting a Javascript error, Basically the page is not getting the HTML containts of the new page, when I do server.transfer. Its still maintains the HTML of the previous page, So when the controls are not found I get a Js error,...

Any help will be useful,
Thanks Very much

hi..
November 16, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

It's working fine without try catch block but once i put in try catch block it's giving me this error. So it's better not to use try catch block

Murugesan Kumarasamy
December 07, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I have the same issue when i try to export the DevExpress GridView rows as Excel sheet.

Sometimes its not exporting the rows which i have selected.

Can anyone guide me..

Rohan Pandit
December 28, 2009

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Guys, Even i had the same problem where i was redirecting it to other page after storing log in name in session but in other page i was checking the wrong session so see if you are doing something like this or not.

Munirul Islam
March 05, 2010

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Yes.. By removing the try catch block my problem has been fixed.

prateek saluja
March 23, 2010

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

i had faced the same problem in case when i was using Response.Redirect("Default.aspx").so i used Response.Redirect("Default.aspx",false) in place of Response.Redirect("Default.aspx").i hope it will help you guys..

maheswaran
April 20, 2010

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Response.Redirect("Default.aspx",false) --thanks guys .. it's working fine ...

aravindhan
April 27, 2010

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Response.Redirect("Formname.aspx",false) or Remove Try Catch block...check it Out Its Working Properly

Ashish
September 07, 2010

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

My problem solved by using
Response.Redirect ("nextpage.aspx", false);

Abdullah
February 17, 2011

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Im facing the same problem. Im working on Windows Application .net VS 2008.( im not using Response.Redirect). I got error when the code that is in thread is completed and call myThread.Abort() method. Any idea t solve the problem?

Felipe
September 26, 2011

# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I was with the same problem, but I was not using "Response.Redirect" in any part of my code.

As the exception (ThreadAbortException) refers to a call to method "Thread.Abort()" I searched for this in my code.

The problem was the Application Timeout that was calling "Thread.Abort()".

Hope it helps.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024