Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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>…
Other Posts you might also like
The Voices of Reason
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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.
# 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. 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
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
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
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
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Thank you!
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
sucessfully.
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
plz help me .
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
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
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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:
# re: 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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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.
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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.
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Any help will be useful,
Thanks Very much
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Sometimes its not exporting the rows which i have selected.
Can anyone guide me..
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
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.
# re: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack