问题
Following the steps from Lesson 3: Load a Report Definition from the Report Server for SQL Server 2012, I have the following error:
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.
When I reached the last line:
_report = (Report)serializer.Deserialize(stream);
To be sure, I had dumped the memory stream into a file, and compare that with the RDL I uploaded into the Report Server, to be exactly the same.
回答1:
At the bottom of this site, https://msdn.microsoft.com/en-us/library/5ad8b31c-43b0-4481-a31b-090cbed4a438(v=sql.105), Mr. Carnessssss managed to solve it this way:
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);
This solves my problem.
回答2:
The correct solution is to replace the XSD in the Lesson 2: Generate Classes from the RDL Schema using the xsd Tool.
From:
http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition/ReportDefinition.xsd
To:
http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition/ReportDefinition.xsd
Not to "hack" it by manipulating its XmlRootAttribute.Namespace, which only good to mask the problem. New problem will emerge when we want to write the serialized object back to the Report Server as I faced here.
来源:https://stackoverflow.com/questions/29098286/error-report-xmlns-nonempty-was-not-expected