【问题标题】:Error <Report xmlns='NonEmpty'> was not expected错误 <Report xmlns='NonEmpty'> 不是预期的
【发布时间】:2015-03-17 11:47:38
【问题描述】:

按照第3: Load a Report Definition from the Report Server for SQL Server 2012课的步骤,我有以下错误:

System.InvalidOperationException was unhandled   
HResult=-2146233079  
Message=There is an error in XML document (2, 2)
.
.
InnerException: System.InvalidOperationException
       HResult=-2146233079
       Message=<Report xmlns='http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition'> was not expected.

当我到达最后一行时:

_report = (Report)serializer.Deserialize(stream);

可以肯定的是,我已将内存流转储到一个文件中,并将其与我上传到报表服务器的 RDL 进行比较,结果完全相同。

【问题讨论】:

  • 我刚刚使用上传到报表服务器的几乎为空的 RDL 文件进行了测试,结果相同。

标签: c# xml reporting-services deserialization xml-deserialization


【解决方案1】:

在本站底部https://msdn.microsoft.com/en-us/library/5ad8b31c-43b0-4481-a31b-090cbed4a438(v=sql.105),Carnessssss 先生设法解决了这个问题:

    XmlRootAttribute xRoot = new XmlRootAttribute();

    xRoot.ElementName = "Report";

    xRoot.Namespace = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";

    xRoot.IsNullable = true;

    XmlSerializer serializer = new XmlSerializer(typeof(RDLSchema), xRoot);

这解决了我的问题。

【讨论】:

    【解决方案2】:

    正确的解决方法是替换Lesson 2: Generate Classes from the RDL Schema using the xsd Tool中的XSD。

    发件人:

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

    收件人:

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

    不要通过操纵其 XmlRootAttribute.Namespace 来“破解”它,这只会掩盖问题。当我们想要将序列化的对象写回报表服务器时,就会出现新的问题,就像我遇到的here

    【讨论】:

      猜你喜欢
      • 2021-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多