Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Error message: System.InvalidCastException: Specified Cast is not valid


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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


Keywords: kb, kbservercontrols, kbprb, kbdsupport, kberrmsg, kbstate

↑ Back to the top

Article Info
Article ID : 327287
Revision : 5
Created on : 8/20/2020
Published on : 8/20/2020
Exists online : False
Views : 98