How to resolve an InvalidCastException in WinForms XPToolBar?
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 an older version and migrated to a later version.
2. If the project is migrated from different versions of the 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 Assembly Manager with the 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 3.5. (You can choose your respective Target Framework)
9. Click OK once the operation is completed successfully.
10. You can also 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 the Bin and Obj folders from the 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 the Product Version (Essential Studio)
5. The issue is resolved.
When the issues still exist, you can get the license key manager details 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. A pop-up dialog box that contains the key is displayed. Select the key that brings up the details of the selected key and send those key details to us to analyze further and provide a 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.