How to fix Error 2358 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 2358 — XML Schema Derivation Conflict

Why This Error Happens

This error occurs when SQL Server’s XML Schema Collection parser encounters a complexType definition that simultaneously declares a base attribute (via restriction or extension) and contains an embedded (anonymous) type definition within the same derivation element. SQL Server 2025’s XML parser does not support this dual-declaration pattern, as it creates ambiguity in how the schema should resolve type inheritance. This typically surfaces when importing third-party XSD files, migrating schema collections from an older SQL Server version, or when a schema was hand-edited and introduced a malformed derivation block.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema File and Location

  • Review the full error message — it includes a Location: '%ls' path pointing to the exact XSD file or XML Schema Collection object causing the conflict.
  • Run the following query to locate the schema collection in question:
  SELECT name, schema_id, xml_schema_namespace 
  FROM sys.xml_schema_collections 
  WHERE name LIKE '%YourSchemaName%';
  • Export the raw schema definition for inspection:
  SELECT xml_schema_namespace(N'dbo', N'YourSchemaCollectionName');

Step 2: Correct the Malformed Complex Type Definition

  • Open the exported XSD in a text editor and search for <xs:complexContent> or <xs:simpleContent> elements that contain both a base="..." attribute and a nested <xs:sequence>, <xs:choice>, or <xs:all> block defined directly alongside it.
  • Separate the derivation logic: either use the base attribute with restriction/extension referencing an already-defined named type, OR define the embedded type anonymously — never both within the same node.
  • Example fix — change this invalid structure:
  <xs:complexType name="Invalid">
    <xs:complexContent>
      <xs:extension base="BaseType">
        <xs:complexType>
          <xs:sequence>...</xs:sequence>
        </xs:complexType>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

to a valid single-level derivation referencing a named type instead of nesting an embedded one.

Step 3: Re-register the XML Schema Collection

  • Drop the broken schema collection (if already partially registered):
  DROP XML SCHEMA COLLECTION dbo.YourSchemaCollectionName;
  • Re-create it using the corrected XSD file:
  CREATE XML SCHEMA COLLECTION dbo.YourSchemaCollectionName 
  AS N'<paste corrected XSD content here>';
  • Confirm there are no residual references in dependent tables or XML columns that still point to the old, invalid schema version.

Step 4: Validate Third-Party or Legacy Schema Sources

  • If the XSD originated from an external vendor or legacy system, check for an updated schema version compatible with SQL Server 2025’s stricter XML parser.
  • Run the corrected file through an independent XSD validator (such as xmllint --schema on Windows via WSL, or Visual Studio’s XML Schema Designer) before re-importing into SQL Server.

Alternative or Verification Steps

  • Verify the fix by re-running the original CREATE XML SCHEMA COLLECTION statement and confirming it completes without Error 2358, then test any dependent stored procedures or XML column constraints that reference the schema.
  • If re-authoring the schema isn’t feasible, use sp_xml_schema_validate or a staging environment on a prior-compatible SQL Server version to pre-process and simplify the schema before migrating it to SQL Server 2025.