How to use dynamic data source in Linq Reporting engine .NET

I had a similar question and found this thread.

This will fail with the exception "Can not get the value of member ‘Name’ on type ‘System.Dynamic.ExpandoObject’."

Template document with the following content:

var doc = new Document(pathToDocTemplate);
dynamic person = new ExpandoObject();
person.Name = “John”;
var engine = new ReportingEngine();
engine.BuildReport(doc, person); //exception thrown here

It would be nice if the reporting engine supports dynamic data source.


Hi Minh,

for your inquiry. I have logged this feature request as WORDSNET-12148 in our issue tracking system. Our development team will look into the
possibility of implementation of this requested feature. Once we have
any information about this feature, we will update you via this thread.

Please let us know if you have any more queries.

Hi Minh,

Further to my last post, we suggest you please use DataSet/DataTable/DataRow objects when dealing with data having dynamic structure. The DataSet class has built-in capabilities to read data from a database or XML file/stream. Also, there are several components enabling to fill a DataSet instance from a JSON string. Moreover, it can be filled manually, if needed.

Note that LINQ Reporting Engine enables to use the same syntax for DataSet/DataTable/DataRow objects (including extension methods) as would be used with regular class instances thus making report templates almost the same in both cases. Please read the following article for more information.
Working with Traditional Mail Merge Data Sources


Thanks for your patience.

Regarding support of dynamic data sources in LINQ Reporting, we have found a workaround involving recently introduced JsonDataSource and Newtonsoft Json.NET . Please check the following code snippet. Hope this helps you.

// Initialize a dynamic object.
dynamic sender = new ExpandoObject();
sender.Message = "Hello";

// Serialize the dynamic object to JSON.
string json = JsonConvert.SerializeObject(sender);

// Initialize a JSON data source.
MemoryStream jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
JsonDataSource dataSource = new JsonDataSource(jsonStream);

// Create a template document.
DocumentBuilder builder = new DocumentBuilder();

// Fill the template with data.
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(builder.Document, dataSource);

// Print the result document.