An exotic DevEx’ ReportDesigner breaking change in 12.2

If you ever customized (excellent) DevExpress ReportDesigner you might have used this line of code to obtain a reference to IDataSourceCollectionProvider within ReportDesigner class which allows to access field list:

IDataSourceCollectionProvider dataSourceCollectionProvider = 
    designerHost.GetDesigner(designerHost.RootComponent) 
    as IDataSourceCollectionProvider;

This code worked well in 12.1 and perhaps in earlier 12.2 versions but it certainly won’t work in 12.2.5. The bad part is that it fails in runtime, while it still compiles perfectly. At least it fails consistently – always. The reason is that access to various services (IDataSourceCollectionProvider is one of them) is now through ReportDesigner.GetService(Type serviceType) method. Replacing the part above with the one below does the trick:

IDataSourceCollectionProvider dataSourceCollectionProvider = 
    (IDataSourceCollectionProvider)designerHost.GetService(
        typeof(IDataSourceCollectionProvider)
    );

The new is more readable and it could be even better if it used generics. I’d certainly consider this declaration instead:

T GetService<T>()
  where T: class
{
   ...
}

which would yield even more readable assignment:

IDataSourceCollectionProvider dataSourceCollectionProvider = 
    designerHost.GetService<IDataSourceCollectionProvider>();

There you have the fix.

Leave a Reply