Articles in this section
Category / Section

How to resolve an InvalidCastException in WinForms gridControl?

2 mins read

Resolve an InvalidCastException

Root Cause

The exception with "System.InvalidCastException: Unable to cast object of type Syncfusion.Windows.Forms.Tools.XPMenus.XPMenusProvider" occurs only in the following scenarios,

1. If the project is created under older version and migrated with later version.

2. If the project is migrated from different versions of framework i.e. 2.0 to 4.0

Solution

You can refer to the following steps in your system to resolve your issues.

1. Open <Essential Studio> Dashboard.

2. Run the AssemblyManger with Removeallversion option. This removes all the Syncfusion assemblies from GAC and public assemblies’ folder.

3. When you find any Syncfusion assemblies in Global Assembly Cache (GAC), you can remove all the Syncfusion assemblies manually.

4. Install the {required version} assemblies.

5. For example, your Target Framework is 3.5, then you can remove 4.0 and 2.0 Syncfusion assemblies from GAC and assembly’s folder and vice versa.

6. Check only required framework assemblies are in GAC (c:\windows\assembly) and also in assemblies folder (C:\Program Files\Syncfusion\Essential Studio\<Product Version> \Assemblies\3.5) (You can choose your respective Target Framework)

7. Open the <Essential Studio> dashboard.

8. Run the Multi Target Framework targeting to 3.5. (You can choose your respective Target Framework)

9. Click OK once operation is completed successfully.

10. Also you can use Toolbox Configuration in Dashboard to install the Syncfusion Tools in Visual Studio

Remove the older version dlls from your application that is found in ReportLib project folder. This should cause the error on handling the form in designer mode to add a new Syncfusion control. Also ensure the older assembly does not get reflected anywhere in the project.

Refer to the following steps to upgrade projects.

1. Remove Bin and Obj folder from Project path.

2. Open the Visual studio IDE and open a project.

3. Rebuild your project.

4. You check that the Syncfusion assemblies are referring to Product Version (Essential Studio)

5. The issue is resolved.

When the issues still exist, you can get the license key manager details that can be achieved by using the following steps.

1. Open the dashboard.

2. Select license manager option that is on left side menu at the bottom.

3. Then press the launch button.

4. Pop-up dialog box is displayed that contains key. Select the key that brings up the details of the selected key and send those key details to us to analyze further and provide better solution.

If still the issue exists, perform a full textual search for old Syncfusion version references in the project. If anything exists, clean all those project files manually and add the correct references.


Conclusion

I hope you enjoyed learning about how to resolve an InvalidCastException.

You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms GridControl example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied