ASP. NET exception: "The expression value cannot be calculated because the code has been optimized or the local framework is located on the call stack." SOLUTION

Source: Internet
Author: User

Today, the project encountered an exception that we have never seen before.CodeI have been optimized or the local framework is located on the call stack and cannot calculate the expression value. "I checked the information and found that this exception was due to the use of" response. end. The solution is as follows:

Exception: The expression value cannot be calculated because the code has been optimized or the local framework is located on the call stack.

Cause:

If you use the response. End, response. Redirect, or server. transfer method, a threadabortexception exception occurs. You can use the try-catch statement to catch this exception.
The response. End method terminates the execution of the page and switches the execution to the application.ProgramApplication_endrequest event in the event pipeline. Do not execute the code line after response. End.
This problem occurs in the response. Redirect and server. transfer methods, because both methods are called internally.Response. End.
Solution:
To solve this problem, use one of the following methods:
• For response. End, call httpcontext. Current. applicationinstance. completerequest instead of response. End to skip the code execution of the application_endrequest event.
•For response. Redirect, use the overload response. Redirect (string URL, bool endresponse). This overload will pass false to the endresponse parameter to cancel internal calls to response. End. For example:
Response. Redirect ("nextpage. aspx", false );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.