DevExpress Report Designer Exception
Sunday, November 6, 2011
Tonight I was greeted with an obscure exception being thrown from the Visual Studio designer when I tried to open a DevExpress report. The application and report worked fine when it was compiled and executed. The stack trace given by Visual Studio designer was not very helpful upon first (and second, and third) glance. A few choice lines from the stack trace (pasting the the complete stack trace would be a bit of an overkill):
at System.Linq.Enumerable.Iterator`1.System.Collections.IEnumerator.Reset() at System.Windows.Forms.ListBindingHelper.GetFirstItemByEnumerable(IEnumerable enumerable) …. at System.Windows.Forms.BindingSource.GetItemProperties(PropertyDescriptor listAccessors)
After several failed attempts at deleting various lines of code in the report.designer file, I finally decided to focus on the Object Binding source (I probably should have started here). While I had been making changes to the domain object I was setting as the binding source, this would have been the first time it caused any type of problem (of course there is a first time for everything).
In the report.designer file I ended up deleting the lines of code that set the data source of the binding source, as well as setting the report’s data source to the binding source. I also saw that I had an actual instance of my domain object being created, and all of it’s public properties getting set. This object was then being used to set the data source of the Binding Source.
this.MyReport.DataSource = MyBindingSource; actualInstanceOfMyDomainObject = new MyDomainObject(); actualInstnaceOfMyDomainObject.Property1 = "Some Value"; …. this.MyBindingSource.DataSource = actualInstanceOfMyDomainObject;
After deleting all of that, I was finally able to open my report once again. I redid the data source bindings and when I reviewed the report.designer file I saw that the binding source was now being set with this one statement:
this.BindingSource.DataSource = typeof(MyDomainObject);
I’m not sure how the designer file got in such a state, but at least I know how to fix it now should it happen again.
Random thought of the day: Flying a plastic airplane with a glass cockpit is fun. All my years of playing Microsoft Flight simulator have finally paid off.