azure-activedirectory-identitymodel-extensions-for-dotnet
azure-activedirectory-identitymodel-extensions-for-dotnet copied to clipboard
WriteXmlnsAttribute in DelegatingXmlDictionaryWriter throws exception
The stack trace
System.ArgumentNullException: Value cannot be null. (Parameter 'localName') at System.Xml.XmlBaseWriter.StartAttribute(String& prefix, String localName, String ns, XmlDictionaryString xNs) at System.Xml.XmlBaseWriter.WriteStartAttribute(String prefix, String localName, String namespaceUri) at System.Xml.XmlDictionaryAsyncCheckWriter.WriteStartAttribute(String prefix, String localName, String ns) at System.Xml.XmlWriter.WriteAttributeString(String prefix, String localName, String ns, String value) at Microsoft.IdentityModel.Xml.DelegatingXmlDictionaryWriter.WriteXmlnsAttribute(String prefix, String namespace)
This happens because the parameters aren't forwarded correctly to the InternalWriter and TracingWriter as seen here.
The correct implementation would be:
public override void WriteXmlnsAttribute(string prefix, string @namespace)
{
UseInnerWriter.WriteXmlnsAttribute(prefix, @namespace);
TracingWriter?.WriteXmlnsAttribute(prefix, @namespace);
InternalWriter?.WriteXmlnsAttribute(prefix, @namespace);
}
or if you want to keep using the WriteAttributeString method:
public override void WriteXmlnsAttribute(string prefix, string @namespace)
{
UseInnerWriter.WriteXmlnsAttribute(prefix, @namespace);
TracingWriter?.WriteAttributeString("xmlns", prefix, null, @namespace);
InternalWriter?.WriteAttributeString("xmlns", prefix, null, @namespace);
}
If anybody out there has this error in their code, a workaround would be to call
WriteAttributeString("xmlns", prefix, null, @namespace);
on their DelegatingXmlDictionaryWriter instead.
@gislikonrad thanks can you provide the code sample that exhibits this?
closing due to inactivity, as we need sample code. Please reopen if we can get a repro and this still happens on the latest 7x version. thank you.