Ticket T308208
Visible to All Users

How to fix the 'Data at the root level is invalid. Line 1, position 1.' exception after setting the ReportsModuleV2.ReportStoreMode property to XML

created 9 years ago (modified 5 years ago)

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:

  1. Back up the application database.

  2. 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(); } }
  1. 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(); } } }
  1. Register an instance of the ReportStoreUpdater class in the GetModuleUpdaters method of the module:
Code
public 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 }; }
  1. Start the application. After successful conversion, remove the ReportStoreUpdater class.
Show previous comments (2)
DevExpress Support Team 6 years ago

    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.

      DevExpress Support Team 5 years ago

        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.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.