Its so surprising to get error while exporting the asp.net web page into excel when we write the code in try catch block. Actually its not the problem of the try catch blcok. ERROR:Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Take a look at the following code.
The above code looks so formal but an error arises…
ERROR:Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
The above error arises bcoz of the Response.End( ); in the above code which aborts the current thread since the request will be ended. To solve the error, you can either remove the try-catch block or if you need to catch the exceptions then you need to catch for ThreadAbortException besides catching for other exceptions. This ThreadAbortException will be caught for nothing.