Hi,
I am generating document using LINQ Reporting which involves inserting images dynamically. I am using JsonDataSource as the datasource.
Getting exception “Buffer cannot be null. Parameter name: buffer”
Json Data
{
“Name”: “Ravi Kashyap”,
“Signature”: “”
}
If I use the concrete type then it works.
I have attached sample code/ project which has th template/ json file as embedded resource.
Can someone please suggest? I have to use jsondatareader as the data is dynamic.
Sample Code:
private static void GenerateDocumentFromJson_NotWorking()
{
byte[] generatedDocument;
// Get Template
var templateContent = ReadResourceData(“Sample_ImageTest01.docx”);
// Get Json Data
var templatDataContent = ReadResourceData("Sample_ImageTest01.json");
// Load the template document.
using (MemoryStream templateStream = new MemoryStream(templateContent))
{
Document doc = new Document(templateStream);
using (MemoryStream dataStream = new MemoryStream(templatDataContent))
{
JsonDataSource jsonDataSource = new JsonDataSource(dataStream);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, jsonDataSource, "data");
// Save the finished document to disk.
using (MemoryStream outStream = new MemoryStream())
{
doc.Save(outStream, SaveFormat.Docx);
generatedDocument = outStream.ToArray();
}
}
File.WriteAllBytes($"Output_Sample_ImageTest01_{ DateTime.Now.ToString("dd_MM_yyyy_hh_mm_s")}.docx", generatedDocument);
}
}
======================
Thanks,
RaviTestAsposeWordReporting.zip (53.9 KB)