Sunday, January 11, 2009

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

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


Cause of Error:
When we call Response.Redirect("") from try/catch block in asp.net, you will receive above error.

Example contains error:
   try
                    {
                        string strRedirectUrl = Session["ReturnUrl"].ToString();
                        Response.Redirect(strRedirectUrl);
                    }
                    catch(Exception ex)
                    {
                        Response.Redirect("Default.aspx");
                    }


Solution:
Make second argument of response.redirect("MyPage.aspx",false);
   
Example containing solution:
try
                    {
                        string strRedirectUrl = Session["ReturnUrl"].ToString();
                        Response.Redirect(strRedirectUrl,false);
                    }
                    catch(Exception ex)
                    {
                        Response.Redirect("Default.aspx");
                    }

1 comment:

Karl said...

This has helped a great deal. Thanks for your input and time to post this..

Most Recent Post

Community Updates

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape