错误<report xmlns =“NonEmpty”>未被预期</report>

时间:2015-03-17 11:47:38

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

按照课程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进行比较,完全相同。

2 个答案:

答案 0 :(得分:0)

在本网站的底部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);

这解决了我的问题。

答案 1 :(得分:0)

正确的解决方案是替换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

不要&#34; hack&#34;它通过操纵它的XmlRootAttribute.Namespace,这只能掩盖问题。当我们在面对here时想要将序列化对象写回报表服务器时,将出现新问题。