Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Symptoms

When you view your ASP.NET page in the browser, you may receive the following error message:

Specified cast is not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Cause

This problem might occur on postback because the control tree hierarchy is re-ordered. On postback, the view state for controls is loaded based on the positions of the controls (indexes) in the control tree. The hierarchy that is created on postback must match the hierarchy that is used initially when the view state is saved.

Resolution

Make sure that the control tree is re-created on postback in the same order that it was saved at the end of the previous request.

Status

This behavior is by design.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×