BusinessList of IInterface

BusinessList of IInterface

Old forum URL: forums.lhotka.net/forums/t/3614.aspx


ajj3085 posted on Friday, September 28, 2007

Hi all,

I just had some really hard to find problems, which centered around ReportViewer, rdlc reports, and BusinessListBase subclasses.

The basic problem is this:  you have a BLB<MyList, ILineItem> so that it can hold any object which implements a particular interface.  In my case, I also have a LineItemBase which all different kinds of line items ultimately inherit from (NoteLineItem, SimpleLineItem, BundleLineItem, etc.).

The problem was showing up as this; my report, which listed the line items in a table, woudl very rarely give me #Error in one or two of the columns.  Additionally, I would get errors if I tried to use a boolean property defined on ILineItem to hide a cell within the table. 

Adding to the frustration, it only happened when items would be in a certain order.  Changing the order of the items would allow everything to work just fine! 

It turns out, that for whatever reason, sometimes, when items where in a certain order (which thankfully, the order was consistent and so I could reproduce the error reliably), a TargetInvokationException was being thrown, due to a type mismatch or something along those lines. 

It seems that for certain properties, on certain types, once the ReportViewer / LocalReport saw the type, it expected the next time in the list to have exactly the same type.  Again, for some reason, changing the order of the items would allow everything to work fine.

The solution I found was to implement ICustomTypeDescriptor on the LineItem base class, so that it always returned information about LineItem.  The reporting tool then uses this information and everything matches, so it seems to be happy.

Just wanted to post on this, because even though others have hit this same problem, it would immedately obvious that this was the cause of my reporting headaches, and I'm not sure how well known this issue is.

I have a sample application which you can use to reproduce the problem; if anyone is interested, I can attach it here.

Andy

Copyright (c) Marimer LLC