{"record":{"id":"5da9d2645f5656c5","repo":"PowerShell/PowerShell","slug":"0-1","errorCode":null,"errorMessage":"{0} {1}","messagePattern":"\\{0\\} \\{1\\}","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs","lineNumber":121,"sourceCode":"                if (e.InnerException is XmlSchemaException schemaException)\n                {\n                    throw new XmlException(schemaException.Message, schemaException, schemaException.LineNumber, schemaException.LinePosition);\n                }\n\n                if (e.InnerException is XmlException xmlException)\n                {\n                    throw xmlException;\n                }\n\n                if (e.InnerException != null)\n                {\n                    string message = string.Format(\n                        CultureInfo.CurrentCulture,\n                        CmdletizationCoreResources.ScriptWriter_ConcatenationOfDeserializationExceptions,\n                        e.Message,\n                        e.InnerException.Message);\n\n                    throw new InvalidOperationException(message, e.InnerException);\n                }\n\n                throw;\n            }\n\n            string objectModelWrapperName = _cmdletizationMetadata.Class.CmdletAdapter ?? defaultObjectModelWrapper;\n            _objectModelWrapper = (Type)LanguagePrimitives.ConvertTo(objectModelWrapperName, typeof(Type), CultureInfo.InvariantCulture);\n            if (_objectModelWrapper.IsGenericType)\n            {\n                string message = string.Format(\n                    CultureInfo.CurrentCulture,\n                    CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperIsStillGeneric,\n                    objectModelWrapperName);\n                throw new XmlException(message);\n            }\n\n            Type baseType = _objectModelWrapper;\n            while ((!baseType.IsGenericType) || baseType.GetGenericTypeDefinition() != typeof(CmdletAdapter<>))","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/PowerShell/PowerShell/blob/3ff3c711bf54a18f8440f3c5190c3ac91cdc5852/src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs#L103-L139","documentation":"Thrown by ScriptWriter's XML deserialization catch block when the Cmdlet Definition XML (CDXML) fails to deserialize and the resulting InvalidOperationException has an inner exception that is neither XmlSchemaException nor XmlException. The message concatenates the outer and inner exception messages to surface both layers of failure. This is a fallback for unexpected deserialization errors (e.g. type binding failures, malformed embedded objects).","triggerScenarios":"Importing a CIM-based PowerShell module whose CDXML file (.cdxml) contains structural XML that passes the reader but fails XmlSerializer deserialization due to a non-schema, non-XML exception — e.g. a type converter error, a circular reference, or a serialization binding failure.","commonSituations":"A CDXML file was hand-edited or generated by a broken tool, introducing a structure that violates the XmlSerializer contract (not just XSD schema). Upgrading PowerShell or the serialization stack changes type resolution behavior for an older CDXML. A third-party CIM module ships a malformed CDXML.","solutions":["Read the full inner exception message in the concatenated text — it identifies the root deserialization failure (type, member, or binding).","Validate the CDXML against the cmdlets-over-objects.xsd schema using an external XML validator to catch structural issues.","Compare the failing CDXML against a known-working CDXML (e.g. from a standard CIM module) to spot the divergent element or attribute.","If the CDXML was machine-generated, regenerate it from the source CIM class definition."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate CDXML by deserializing with an XmlSerializer before module import.\nusing System.Xml.Serialization;\nusing System.Xml;\nusing System.IO;\n\nstatic bool TryValidateCdxml(string path, out string error)\n{\n    error = null;\n    try\n    {\n        var serializer = new XmlSerializer(typeof(Microsoft.PowerShell.Cmdletization.Xml.CmdletsOverObjects));\n        using var reader = XmlReader.Create(path);\n        serializer.Deserialize(reader);\n        return true;\n    }\n    catch (Exception ex)\n    {\n        error = $\"{ex.Message} -> {ex.InnerException?.Message}\";\n        return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"// Catch the InvalidOperationException at module import and surface the inner exception.\ntry\n{\n    Import-Module MyCimModule;\n}\ncatch [System.InvalidOperationException]\n{\n    # The message contains concatenated outer+inner exception text.\n    Write-Error $_.Exception.Message;\n}","preventionTips":["Validate CDXML files against the cmdlets-over-objects XSD schema before deploying or importing.","Use the XmlSerializer to test-deserialize CDXML in a build step to catch non-schema deserialization errors early.","Keep CDXML generation automated (from CIM class tooling) rather than hand-editing to avoid structural corruption."],"tags":["cdxml","cmdletization","xml","deserialization","cim","powershell"],"backgroundTag":null,"analyzedSha":"3ff3c711bf54a18f8440f3c5190c3ac91cdc5852","analyzedAt":"2026-08-13T10:39:10.759Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}