Error rendering control (Unable to cast object of TypeA to TypeA)

1 posts, 1 answers
  1. Answer
    Telerik Admin
    Telerik Admin avatar
    1628 posts
    Member since:
    Oct 2004

    Posted 28 Jul 2010 Link to this post

    Hi all,

    Recently we discovered that Visual Studio can sporadicaly display the "Error rendering control" message in design time.
    This can occur in several specific error messages:
    • [A]Telerik.Web.UI.RadScriptManager cannot be cast to [B]Telerik.Web.UI.RadScriptManager. Type A originates from...
    • Unable to cast object of type 'Telerik.Web.UI.RadScriptManager' to 'Telerik.Web.UI.RadScriptManager'
    • Unable to cast object of type Telerik.Web.UI.[ControlName] to Telerik.Web.UI.ControlItemContainer

    The screenshots below demonstrate sample occurrences of the error:

    A subsequent close of the page in design time and a further reload usually might make it render correctly. A further close and reload can cause the error to reappear though.

    Our research showed that some registry entries we use to enable Visual Studio display RadControls in the "Add Reference" and "Choose ToolBox Items" dialogs are the reason for the error. It seems that for some reason Visual Studio loads several instances of the Telerik.Web.UI assembly into its AppDomain, which results in the error above.
    We decided to sacrifice the appearance of the Telerik.Web.UI assembly in the above mentioned dialogs, but prevent this annoying error from happening and we already removed the registry entries from the RadControls installers.

    As a fix in the meantime, you could use the .reg files in the attached archives (one targets a 32-bit machine and the other targets a 64-bit one) and the .bat files (targeting Windows XP and Windows7/Vista respectively) to fix the problem. Here are the steps to follow:
    1. Download and extract the archive to a folder of your choice
    2. Close all Visual Studio instances
    3. Double-click the .reg file (use the Remove_AssemblyFoldersEx_32bitMachine.reg for 32-bit machines and the  Remove_AssemblyFoldersEx_64bitMachine.reg one for 64-bit machines) and click the 'Yes' button when asked to confirm the registry entry merge
    4. Double-click the bat file, depending on the Windows system you're running (use the ClearProjectAssemblies_Win7_Vista.bat for Windows7/Vista and the ClearProjectAssemblies_WinXP.bat for Windows XP)
    5. Start Visual Studio and load your project

    Kind regards,
    Erjan Gavalji
Back to Top