locked
Error on loading RDLC serialzation into class RRS feed

  • Question

  • Hi, I am trying to modify rdlc report spec at runtime by loading the file into a report object before opening the reportviewer. In using the xsd file from the above site the deserialize generates an exception on the first line indicating it is unexpected. (Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition"). I have tried to generate an xsd from the specific report but xsd.exe complains about nested classes. I wanted to try infer.exe but have not been able to find a copy. Any suggestions would be very much appreciated. Thanks.      (VS 2008, SQL Server 2005, Windows 7, VB or C#, ASP.NET)
    Saturday, October 23, 2010 11:01 PM

Answers

  • Tony,

    The issue turned out to be a namespace problem that I am working through. What I had done is exacly what you have suggested.  Thanks for your help.

    Alan

    • Marked as answer by ahaskins Tuesday, October 26, 2010 2:50 PM
    Tuesday, October 26, 2010 2:50 PM

All replies

  • Hi,

     

    It seems that you ran into the problem by referring the incorrect version of report definition schema to generate report classes.

     

    Since Visual Studio 2008 only supports RDLC 2005, we need to generate report classes based on the report definition schema version 2005 below:

    http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition/ReportDefinition.xsd

     

    Then we can reference the generated report classes into project and deserialize the RDLC file to report objects.

     

    If you have any more question, please feel free to ask.

     

    Thanks,

    Tony Chain


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Monday, October 25, 2010 2:57 AM
  • Tony,

     

    Thanks, but I should have noted that the class was indeed generated from http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition .  Have you done this with success? Note that the 27th line of the generated class is:      System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition", IsNullable:=False)> _

     

    Thanks,

    Alan

    Monday, October 25, 2010 1:34 PM
  • Hi,

     

    I cannot open the link you posted, could you please check if the URL is correct and the thread still exists?

     

    To generate classes from Report Definition Schema, I have achieved by the following steps:

    1.    Open the http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition/ReportDefinition.xsd in the browser, and then save the schema on the local disk.

    2.    After the file has been saved, open an instance of the Visual Studio 2008 Command Prompt.

    To open an instance of the command prompt, point to the Start menu, point to All Programs, point to Microsoft Visual Studio 2008, point to Visual Studio Tools and click Visual Studio 2008 Command Prompt.

    3.    Change the current path to the location where you saved the ReportDefinition.xsd file:

    CD\<ReportDefinition.xsd Path>

    4.    Generate the ReportDefinition.cs file that contains the classes for the schema with the following command:

    xsd /c /n:SampleRDLSchema ReportDefinition.xsd

    To generate a ReportDefinition.vb file use this command:

    xsd /c /l:VB /n:SampleRDLSchema ReportDefinition.xsd

    The argument SampleRDLSchema indicates the namespace in generated class definition file.

     

    After these steps, a ReportDefinition.cs will be generated.  Then we need to add it to the project. Please refer to the following steps:

    1.    In Visual Studio Right click the project name in the Solution Explorer, click Add Existing Item. Browse to the location where you generated the ReportDefinition.cs (.vb) file, select the file, and click Add.

    2.    To deserialize the RDLC file to object, please refer to the code below

    using SampleRDLSchema;

    using System.Xml.Serialization;

    using System.IO;

    Report report;

    XmlSerializer serializer = new XmlSerializer(typeof(Report));

    Stream reader = new FileStream("Report1.rdlc", FileMode.Open);

    report = (Report)serializer.Deserialize(reader);

     

    The Report class is defined in the ReportDefinition.cs file, we can also use classes defined in this file to access the report object.

     

    There is another similar Tutorial you can refer to: http://msdn.microsoft.com/en-us/library/aa337451(v=SQL.90).aspx

     

    If anything unclear or you have any more questions, please feel free to ask

     

    Thanks,

    Tony Chain


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    • Proposed as answer by Tony Chain Wednesday, October 27, 2010 12:56 AM
    Tuesday, October 26, 2010 5:56 AM
  • Tony,

    The issue turned out to be a namespace problem that I am working through. What I had done is exacly what you have suggested.  Thanks for your help.

    Alan

    • Marked as answer by ahaskins Tuesday, October 26, 2010 2:50 PM
    Tuesday, October 26, 2010 2:50 PM