C# – Flexible reporting system with dynamically loaded assemblies


I want to build a flexible reporting system for my application. So far I only have a concept in my head and need some tips on implementation. I'm using Crystal Reports to render reports and I know how to load reports dynamically.

Now, the idea is that every report will be packaged as a separate assembly (.dll). The reporting framework will be loading every custom report and communicating with it via clearly defined interface like this:

public interface IReport
    string GetTitle();
    string GetDescription();
    void SetParameter();
    void Print();

Also, there will be some base implementation (as an abstract class) that will handle some common operations on the reports (like binding to data source, etc.):

public abstract class Report

Inside every dll there will be an implementation of concrete class, representing this or that report:

public class CustomersReport : Report

Now, I have to figure out the following:

1) How to dynamically locate and load the dll?

2) How to create an instance of concrete class (CustomerReport) and cast it to IReport in order to call necessary methods on it?

Have you ever implemented such an extensible system? Could you please share your expertise / code snippets?

Thanks in advance.


While investigating this question I found Jon Skeet's article on Plug-ins and Cast Exceptions that might be helpful.

Best Solution

See this: Problem with dynamic loading of a dll into my program Is doing exactly what you want wihtout all the YAGNI around it.

Related Question