internal Stream UpgradeToCurrent(Stream stream, ref Stream outStream)
            {
                XmlElement documentElement = LoadDefinition(stream).DocumentElement;

                ScanRdlNamespace(documentElement);
                if (NeedsUpgrade)
                {
                    string oldRdlNamespace = OldRdlNamespace;
                    if (!(oldRdlNamespace == "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"))
                    {
                        if (!(oldRdlNamespace == "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition"))
                        {
                            throw new RDLUpgradeException(RDLUpgradeStrings.rdlInvalidTargetNamespace(OldRdlNamespace));
                        }
                    }
                    else
                    {
                        UpdateNamespaceURI("http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition", "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition");
                    }
                }
                return(SaveDefinition(ref outStream));
            }
            private Stream UpgradeUnified(Stream stream, XmlReader xmlReader, string namespaceURI, bool throwUpgradeException, bool upgradeDundasCRIToNative, bool renameInvalidDataSources, out RDLUpgradeResult upgradeResults)
            {
                if (stream == null && xmlReader == null)
                {
                    throw new ArgumentNullException("Stream or XmlReader must be non-null");
                }
                if (xmlReader != null && namespaceURI == null)
                {
                    throw new ArgumentException("namespaceURI must not be null if xmlReader is specified");
                }
                if (namespaceURI == null)
                {
                    xmlReader = CreateXmlReader(stream);
                    xmlReader.MoveToContent();
                    namespaceURI = xmlReader.NamespaceURI;
                    xmlReader.Close();
                    xmlReader = null;
                    stream.Seek(0L, SeekOrigin.Begin);
                }
                upgradeResults = null;
                switch (namespaceURI)
                {
                case "http://schemas.microsoft.com/SQLServer/reporting/reportdefinition-1":
                case "http://schemas.microsoft.com/SQLServer/reporting/reportdefinition-2":
                case "http://schemas.microsoft.com/sqlserver/reporting/2003/04/reportdefinition":
                case "http://schemas.microsoft.com/sqlserver/reporting/2003/04/reportdefinition-1":
                case "http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition":
                    LoadDefinitionXml(ref xmlReader, stream, preserveWhitespace: false);
                    stream = SaveDefinitionXml();
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition":
                    stream = UpgradeFrom200501(EnsureReaderSetup(xmlReader, stream), throwUpgradeException, upgradeDundasCRIToNative, renameInvalidDataSources, out upgradeResults);
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2007/01/reportdefinition":
                    LoadDefinitionXml(ref xmlReader, stream, preserveWhitespace: true);
                    UpgradeFrom200701();
                    stream = SaveDefinitionXml();
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition":
                    stream = UpgradeFrom200801(EnsureReaderSetup(xmlReader, stream), out upgradeResults);
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2009/01/reportdefinition":
                    LoadDefinitionXml(ref xmlReader, stream, preserveWhitespace: true);
                    UpgradeFrom200901();
                    stream = SaveDefinitionXml();
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition":
                    stream = UpgradeFrom201001(EnsureReaderSetup(xmlReader, stream), out upgradeResults);
                    goto case "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition";

                case "http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition":
                    if (upgradeResults == null)
                    {
                        upgradeResults = new RDLUpgradeResult();
                    }
                    if (stream == null)
                    {
                        LoadDefinitionXml(ref xmlReader, stream, preserveWhitespace: true);
                        stream = SaveDefinitionXml();
                    }
                    return(stream);

                default:
                    throw new RDLUpgradeException(RDLUpgradeStrings.rdlInvalidTargetNamespace(namespaceURI));
                }
            }