私は非常に奇妙な状況があります。C#XMLシリアル化:名前空間宣言の順序
:私は同じソフトウェアでこれを入手buildserverはオン<SystemConfiguration
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.schaeffler.com/sara/systemconfiguration/">
:私のマシン上で
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
serializer.Serialize(writer, config, namespaces);
私は、次のxml(1つのラインIだけ追加改行)を取得:私はこのように私の名前空間をシリアル化
<SystemConfiguration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.schaeffler.com/sara/systemconfiguration/">
xsdとxsiの順序が入れ替わっています。シリアライザの実装をチェックし、その順序がハッシュテーブルで決定され、XmlSerializerNamespacesがネームスペース用に独自のシリアライザを実装するためのインターフェイスがないことがわかりました。
これはXmlSerializationWriterにおける方法であって、ハッシュマップ内の名前空間の異なる順序を引き起こす可能性がありますどのような
protected void WriteNamespaceDeclarations(XmlSerializerNamespaces xmlns)
{
if (xmlns != null)
{
foreach (DictionaryEntry dictionaryEntry in xmlns.Namespaces)
{
string localName = (string) dictionaryEntry.Key;
string ns = (string) dictionaryEntry.Value;
if (this.namespaces != null)
{
string str = this.namespaces.Namespaces[(object) localName] as string;
if (str != null && str != ns)
throw new InvalidOperationException(Res.GetString("XmlDuplicateNs", (object) localName, (object) ns));
}
string str1 = ns == null || ns.Length == 0 ? (string) null : this.Writer.LookupPrefix(ns);
if (str1 == null || str1 != localName)
this.WriteAttribute("xmlns", localName, (string) null, ns);
}
}
this.namespaces = (XmlSerializerNamespaces) null;
}
? MSDNから