Description:
After setting the ReportsModuleV2.ReportStoreMode property to XML, an existing report cannot be opened and the 'Data at the root level is invalid. Line 1, position 1. ' exception occurs.
Answer:
Existing reports are still stored in DOM mode in the database, so they cannot be loaded in XML mode. To convert the reports from DOM to XML, do the following:
-
Back up the application database.
-
Add the following ModuleUpdater descendant class to the module project.
Version 19.1+:
C#public class ReportStoreUpdater : ModuleUpdater {
public ReportStoreUpdater(IObjectSpace objectSpace, Version currentDBVersion)
: base(objectSpace, currentDBVersion) {
}
public override void UpdateDatabaseAfterUpdateSchema() {
base.UpdateDatabaseAfterUpdateSchema();
var oldReportData = ObjectSpace.CreateCollection(typeof(ReportDataV2), new BinaryOperator("IsPredefined", false));
foreach(ReportDataV2 reportData in oldReportData) {
XtraReport report = ReportDataProvider.ReportsStorage.LoadReport(reportData);
ReportDataProvider.ReportsStorage.SaveReport(reportData, report);
}
ObjectSpace.CommitChanges();
}
}
- Add the following line to the Application_Start method of the Global.asax file in your SolutionName.Web project:
C#DevExpress.Security.Resources.AccessSettings.ReportingSpecificResources.SetRules(DevExpress.XtraReports.Security.SerializationFormatRule.Allow(SerializationFormat.Code, SerializationFormat.Xml));
Before 19.1:
C#public class ReportStoreUpdater : ModuleUpdater {
ReportStoreModes storeMode;
public ReportStoreUpdater(IObjectSpace objectSpace, Version currentDBVersion, ReportStoreModes newStoreMode)
: base(objectSpace, currentDBVersion) {
storeMode = newStoreMode;
}
public override void UpdateDatabaseAfterUpdateSchema() {
base.UpdateDatabaseAfterUpdateSchema();
var oldReportData = ObjectSpace.CreateCollection(typeof(ReportDataV2), new BinaryOperator("IsPredefined", false));
foreach(ReportDataV2 reportData in oldReportData) {
XtraReport report = LoadReport(reportData);
((IReportDataV2Writable)reportData).SetContent(GetBuffer(report));
}
ObjectSpace.CommitChanges();
}
private XtraReport LoadReport(ReportDataV2 reportData) {
byte[] content = reportData.Content;
XtraReport report = new XtraReport();
if(content != null && content.Length > 0) {
int realLength = content.Length;
while(content[realLength - 1] == 0) {
realLength--;
}
MemoryStream stream = new MemoryStream(content, 0, realLength);
if(storeMode == ReportStoreModes.XML) {
report.LoadLayout(stream);
}
else {
report.LoadLayoutFromXml(stream);
}
stream.Close();
}
return report;
}
private byte[] GetBuffer(XtraReport report) {
using(MemoryStream stream = new MemoryStream()) {
if(storeMode == ReportStoreModes.XML) {
report.SaveLayoutToXml(stream);
}
else {
report.SaveLayout(stream, true);
}
return stream.ToArray();
}
}
}
- Register an instance of the ReportStoreUpdater class in the GetModuleUpdaters method of the module:
Codepublic override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
ReportStoreUpdater converter = new ReportStoreUpdater(objectSpace, versionFromDB, ReportStoreModes.XML);
return new ModuleUpdater[] { updater, converter };
}
- Start the application. After successful conversion, remove the ReportStoreUpdater class.
After v19.1 loading reports stored in the DOM format is blocked. Call the following line to temporarily disable this restriction.
Hello Nathan,
We need additional time to answer your question. Please bear with us. We will get back to you as soon as possible.
Note that the loading of the reports stored in the DOM format is blocked only in Web applications as described at Web Reporting - Deserialization from the CodeDOM format has been disabled.
I have updated the original solution with the updater for version 19.1.
Trying to convert my existing ReportsV2 reports in 19.1.6 update to the XML format. I'm getting a "Rules have already been set" error.
When I look at the watch window, I see the rules, but can't figure out how to remove or change them.
Hello Randy,
I've created a separate ticket on your behalf (T826699: Reports - Why the "Rules have already been set" error occurs). It has been placed in our processing queue and will be answered shortly.