DevExpress XtraReport Designer Error Fix - FalconFT/FalconDocs GitHub Wiki
DevExpress XtraReport Designer Error Fix
Issue Description
When attempting to open DevExpress XtraReport files (e.g., Cover2.cs, Cover.cs, BackCover.cs, CoverTax.cs, NoteReport.cs) in the Visual Studio designer, the following error was displayed:
Error Message:
"To prevent possible data loss before loading the designer, the following errors must be resolved:
Object does not match target type."
The error appeared in a dialog with "Ignore and Continue" option, but clicking it caused the same error to reappear in a loop, preventing the designer from opening.
Root Cause
The error was caused by a type mismatch in the designer serialization. The reports were using System.Windows.Forms.BindingSource for the mainEntityDataSource component, but DevExpress XtraReports requires DevExpress.DataAccess.ObjectBinding.ObjectDataSource for proper data binding and designer serialization.
This type mismatch caused the designer to fail during the deserialization process when attempting to load the report layout.
Solution
The solution involved replacing System.Windows.Forms.BindingSource with DevExpress.DataAccess.ObjectBinding.ObjectDataSource for the mainEntityDataSource component in all affected reports.
Example: Changes Applied to Cover2.Designer.cs
1. Changed the Component Initialization
Before:
private void InitializeComponent()
{
// ... other code ...
this.mainEntityDataSource = new System.Windows.Forms.BindingSource();
// ... other code ...
}
After:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
// ... other code ...
this.mainEntityDataSource = new DevExpress.DataAccess.ObjectBinding.ObjectDataSource(this.components);
// ... other code ...
}
2. Added Name Property to DataSource Configuration
Before:
// mainEntityDataSource
//
this.mainEntityDataSource.DataSource = typeof(Falcon.Model.DTO.Entities.IEntityDTO);
After:
// mainEntityDataSource
//
this.mainEntityDataSource.DataSource = typeof(global::Falcon.Model.DTO.Entities.IEntityDTO);
this.mainEntityDataSource.Name = "mainEntityDataSource";
3. Added DataSource to ComponentStorage
Before:
this.ComponentStorage.AddRange(new System.ComponentModel.IComponent[] {
this.coverInfoObjectDataSource});
After:
this.ComponentStorage.AddRange(new System.ComponentModel.IComponent[] {
this.coverInfoObjectDataSource,
this.mainEntityDataSource});
4. Updated Field Declaration
Before:
private System.Windows.Forms.BindingSource mainEntityDataSource;
After:
private DevExpress.DataAccess.ObjectBinding.ObjectDataSource mainEntityDataSource;
5. Added Component Container Support
The ObjectDataSource requires initialization with the component container:
Before:
((System.ComponentModel.ISupportInitialize)(this.mainEntityDataSource)).BeginInit();
// ... rest of InitializeComponent ...
((System.ComponentModel.ISupportInitialize)(this.mainEntityDataSource)).EndInit();
After:
The same pattern is maintained, but now properly initializes DevExpress.DataAccess.ObjectBinding.ObjectDataSource instead of System.Windows.Forms.BindingSource.
Reports Fixed
The following reports were updated with the same changes:
- ✅ Cover2.cs - Cover report (A4 landscape)
- ✅ Cover.cs - Main cover report
- ✅ BackCover.cs - Back cover with disclaimer
- ✅ CoverTax.cs - Tax information cover
- ✅ NoteReport.cs - Notes report
Verification
After applying these changes:
- ✅ All reports compile successfully without errors
- ✅ The DevExpress Report Designer opens without displaying the error dialog
- ✅ Data bindings function correctly at runtime
- ✅ The
mainEntityDataSourceis properly managed by the component storage system
Technical Notes
Why ObjectDataSource?
- DevExpress XtraReports are designed to work with
DevExpress.DataAccess.ObjectBinding.ObjectDataSourcefor object data binding System.Windows.Forms.BindingSourceis a Windows Forms component not compatible with DevExpress report serialization- The
ObjectDataSourceprovides proper design-time support and type safety for DevExpress reports
Component Storage
Adding the data source to ComponentStorage ensures:
- Proper component lifecycle management
- Correct serialization/deserialization in the designer
- Integration with DevExpress report infrastructure
Project Information
- Target Framework: .NET 8
- DevExpress Version: 25.1 (as indicated in
Cover2.Designer.cs) - Project: Falcon.Client.Analysis
- Namespace: Falcon.Client.Analysis.Modules.Reports.Portfolio
Conclusion
This fix resolves the designer loading issue by ensuring all data sources use the correct DevExpress-compatible type. The reports now open successfully in the designer and maintain their data binding functionality at runtime.