Unable to evaluate expression because code is optimized or native frame on top of the call stack! [Resolved]

Posted by Coolbharat under ASP.NET on 2/7/2014 | Points: 10 | Views : 6181 | Status : [Member] | Replies : 1
I wrote some code with response.redirect() and server.transfer() for transffering from one page to another
without any try and catch block which worked fine.But as soon as i put try and catch block it gave a strange exception
"Unable to evaluate the expression because the code is optimized or a native frame on top of the call stack".I assume it is because of ThreadAbort Exception.So i added another parameter "false" to response.redirect().But what to with server.trtansfer().What i found was to use server.execute() method instead of server.transfer().I don't know how to use it.Please help me out.

Thanks in advance




Responses

Posted by: Sravan661 on: 2/7/2014 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

When Server.Execute is used, a URL is passed to it as a parameter, and the control moves to this new page. Execution of code happens on the new page. Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server.Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control is'nt returned to the calling page).
In both the cases, the URL in the browser remains the first page url (does'nt refresh to the new page URL) as the browser is'nt requested to do so.
This is how to exeecte it
Server.Execute("Login.aspx", writer);



I hope if it is ThreadAbort Exception try this code instead of server.Execute

catch (ThreadAbortException)

{

}

catch (Exception)

{

Response.Redirect("~/Error.aspx");

}

Hope it helps you
mark as answer if it helps you


sravan

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response