diff --git a/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs b/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs index 1e3c38ce0b532..a5f00bb0993d2 100644 --- a/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs +++ b/src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs @@ -1403,7 +1403,7 @@ private string FindTargetNamespace(DataTable table) } } } - else + else if(_ds != null) { // if it does not have any parent table , then it should inherit NS from DataSet tgNamespace = _ds!.Namespace; } @@ -1507,7 +1507,7 @@ internal XmlElement HandleColumn(DataColumn col, XmlDocument dc, XmlElement sche schNode.AppendChild(root); root = _dc.CreateElement(Keywords.XSD_PREFIX, refString, Keywords.XSDNS); root.SetAttribute(Keywords.REF, _prefixes[col.Namespace] + ":" + col.EncodedColumnName); - if (col.Table.Namespace != _ds!.Namespace) + if (col.Table.Namespace != _ds?.Namespace) { _ = GetSchema(col.Table.Namespace); }