DevExpress Error 02: Unable to cast object of type 'myDevices.SmokeMeasurement.Mexa1170.Configuration.Mexa1170ConfigurationUserControl' to type 'DevExpress.XtraEditors.XtraUserControl' ?
This error message:
Unable to cast object of type 'myDevices.Devices.SmokeMeasurement.Mexa1170.Configuration.Mexa1170ConfigurationUserControl' to type 'DevExpress.XtraEditors.XtraUserControl'.
…usually means that the class Mexa1170ConfigurationUserControl
does not inherit from DevExpress.XtraEditors.XtraUserControl
— or there’s an issue with assembly references. Let’s troubleshoot step by step.
1. Confirm inheritance
Check if the Mexa1170ConfigurationUserControl
class properly inherits from XtraUserControl
.
In Mexa1170ConfigurationUserControl.cs
:
using DevExpress.XtraEditors;
namespace myDevices.SmokeMeasurement.Mexa1170.Configuration
{
public class Mexa1170ConfigurationUserControl : XtraUserControl
{
public Mexa1170ConfigurationUserControl()
{
InitializeComponent();
}
}
}
If it does not inherit, you’ll see this error when you try to cast.
2. Check for assembly mismatches
Sometimes the DevExpress assembly versions differ across projects, which can lead to casting issues. Make sure:
- All projects reference the same version of
DevExpress.XtraEditors.dll
. - Use NuGet Package Manager or Reference Properties in Visual Studio to confirm this.
3. Clean and rebuild the solution
Sometimes the issue comes from stale builds.
- Clean Solution → Rebuild Solution in Visual Studio.
4. Ensure no duplicate DevExpress references
Check that no project references multiple versions of DevExpress.XtraEditors.dll
. You can do this in the References section of your project.
5. Check the DevExpress.XtraEditors
version in the GAC
If you’re using assemblies from the GAC, sometimes older versions cause this error. You can check the versions in the GAC using:
gacutil -l DevExpress.XtraEditors
6. Check runtime assembly binding
If your app uses different versions at runtime, add a binding redirect in your .config
file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DevExpress.XtraEditors" publicKeyToken="b88d1754d700e49a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-23.1.5.0" newVersion="23.1.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
(Replace the version and public key token with your DevExpress version.)
7. Confirm the object type
If you're getting the object from reflection or a dynamic source, confirm the actual type:
var control = someObject as DevExpress.XtraEditors.XtraUserControl;
if (control == null)
{
Console.WriteLine(someObject.GetType().FullName);
}
8. Last resort: Decompile and inspect
If nothing else works, use ILSpy or dnSpy to decompile and confirm the base class of Mexa1170ConfigurationUserControl
.
If you like comment and share. 🚀
0 Comments