Reputation: 2518
I'm using VS 2008 to generate a Reporting Services report definition. The problem is that whenever I try to load a report definition from a stream I get an error.
I have the following code:
var loaded = XDocument.Load(filePath);
LocalReport ret = new LocalReport();
using (var stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
loaded.Save(writer);
var ret = new LocalReport();
ret.LoadReportDefinition(stream);
var r= ret.GetParameters();
}
When the last line is executing it throws LocalProcessingException with the followinf text:
{"The report definition is not valid. Details: O elemento raiz está em falta."}
The details translate to "root element missing".
What could be wrong?
Edit: The XML definition is correct. The problem lies somewhere after the loading of the definition.
Upvotes: 1
Views: 1586
Reputation: 481
You must reset the stream back to position 0 before reading it again. Otherwise LoadReportDefinition
will start to read from the end of the stream.
var loaded = XDocument.Load(filePath);
LocalReport ret = new LocalReport();
using (var stream = new MemoryStream())
{
var writer = new StreamWriter(stream);
loaded.Save(writer);
writer.Close();
writer.Position = 0;
var ret = new LocalReport();
ret.LoadReportDefinition(stream);
var r= ret.GetParameters();
}
See CreateMemoryStream() on this page
Upvotes: 2
Reputation: 62027
Have you tried saving the MemoryStream down to a separate file and comparing it to the original?
Upvotes: 0