0XC00D138B

NS_E_NAMESPACE_WRONG_TYPE (0XC00D138B) fix — XML namespace mismatch

Windows Errors Intermediate 👁 0 views 📅 May 27, 2026

Happens when you try to write a value into an XML namespace node that's locked to a different type. Usually from bad XSLT or misconfigured XML serializers.

This error hits you right when you're trying to stuff a value into an XML namespace node that's already been assigned a different data type. I've seen this most often in two places: custom Windows Media Player plugins that mess with playlist metadata, and old-school XSLT transforms where someone's trying to set an attribute value on a namespace declaration node. Another common trigger: using IXMLDOMDocument2 or MSXML and accidentally trying to set .text or .nodeValue on a namespace node instead of an element or attribute.

The root cause is simple: namespace nodes in the XML DOM are read-only for their type. You can't change a namespace declaration (xmlns:foo="http://bar") into an attribute, or an element into a namespace. The error code 0XC00D138B is COM's way of yelling "wrong type, pal." Once the parser sets the namespace node's type (like NODE_NAMESPACE), any attempt to assign a value that doesn't match that type throws this.

How to fix it

  1. Identify the exact node causing the problem. In your code, add a debug step to print the nodeType and nodeName of the node you're writing to. In MSXML, nodeType 9 is NODE_NAMESPACE. If it's 9, you can't set a value directly.
  2. Change your code to target the right node. If you need to change a namespace URI, you have to remove the old namespace declaration and add a new one. You can't just set .text on it. Here's the pattern in MSXML (VBScript example, but the logic holds for C++/C#):
    Set oldAttr = doc.selectSingleNode("//@xmlns:oldprefix")
    Set newAttr = doc.createAttribute("xmlns:newprefix")
    newAttr.nodeValue = "http://newuri.com"
    doc.documentElement.setAttributeNode(newAttr)
    oldAttr.parentNode.removeAttributeNode(oldAttr)
    
    Note: If you're in .NET with XmlDocument, use SetAttribute with the namespace — don't touch the XmlAttribute object for the xmlns declaration itself.
  3. If it's from XSLT, check your output method. I've seen this when someone sets xsl:output method="text" but then tries to write namespace nodes. Switch to method="xml" or method="html" and apply namespaces correctly in the stylesheet.
  4. For Windows Media Player plugin issues: The playlist XML expects specific elements like <seq> and <media>. Don't set .text on a node that's auto-generated by the player's XML parser. Instead, use the IWMPPlaylist interface methods to modify the playlist, then let the player serialize it.

Still failing? Check these three things

  • Are you calling put_nodeValue on a namespace node? Just don't. Validate nodeType before any put_text or put_nodeValue call. If it's NODE_NAMESPACE, skip or restructure.
  • Is your XML well-formed? Namespace declarations must come before any child elements or attributes that use them. If you're trying to set a namespace value on a node that's already been used in a parent scope, the parser may have already locked its type.
  • Version mismatch? MSXML 3.0 and 6.0 handle namespace nodes differently. MSXML 3.0 is more relaxed and might let you get away with it. If you're targeting MSXML 6.0, it's stricter — that's probably where you're hitting this. Switch to the same version across your app.

Had a client last month who was building a playlist editor for a radio station. Their import script kept throwing 0XC00D138B every time they loaded a custom XML file. Turns out they were trying to set the xmlns:media attribute's value directly. Switched to using setAttributeNS and it worked clean. The error never came back.

If you're still stuck, post the snippet around the line that triggers it. The fix is usually one line — you're just aiming at the wrong node.

Was this solution helpful?