PowerShell/PowerShell · error · InvalidOperationException
{0} {1}
Error message
{0} {1} What it means
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).
Source
Thrown at src/System.Management.Automation/cimSupport/cmdletization/ScriptWriter.cs:121
if (e.InnerException is XmlSchemaException schemaException)
{
throw new XmlException(schemaException.Message, schemaException, schemaException.LineNumber, schemaException.LinePosition);
}
if (e.InnerException is XmlException xmlException)
{
throw xmlException;
}
if (e.InnerException != null)
{
string message = string.Format(
CultureInfo.CurrentCulture,
CmdletizationCoreResources.ScriptWriter_ConcatenationOfDeserializationExceptions,
e.Message,
e.InnerException.Message);
throw new InvalidOperationException(message, e.InnerException);
}
throw;
}
string objectModelWrapperName = _cmdletizationMetadata.Class.CmdletAdapter ?? defaultObjectModelWrapper;
_objectModelWrapper = (Type)LanguagePrimitives.ConvertTo(objectModelWrapperName, typeof(Type), CultureInfo.InvariantCulture);
if (_objectModelWrapper.IsGenericType)
{
string message = string.Format(
CultureInfo.CurrentCulture,
CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperIsStillGeneric,
objectModelWrapperName);
throw new XmlException(message);
}
Type baseType = _objectModelWrapper;
while ((!baseType.IsGenericType) || baseType.GetGenericTypeDefinition() != typeof(CmdletAdapter<>))View on GitHub (pinned to 3ff3c711bf)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate CDXML by deserializing with an XmlSerializer before module import.
using System.Xml.Serialization;
using System.Xml;
using System.IO;
static bool TryValidateCdxml(string path, out string error)
{
error = null;
try
{
var serializer = new XmlSerializer(typeof(Microsoft.PowerShell.Cmdletization.Xml.CmdletsOverObjects));
using var reader = XmlReader.Create(path);
serializer.Deserialize(reader);
return true;
}
catch (Exception ex)
{
error = $"{ex.Message} -> {ex.InnerException?.Message}";
return false;
}
} Try / catch
// Catch the InvalidOperationException at module import and surface the inner exception.
try
{
Import-Module MyCimModule;
}
catch [System.InvalidOperationException]
{
# The message contains concatenated outer+inner exception text.
Write-Error $_.Exception.Message;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot process the ObjectModelWrapper attribute. The {0} typ
- Cannot process the ObjectModelWrapper attribute. The {0} typ
- Cannot process the ObjectModelWrapper attribute. The {0} typ
- Cannot process the ObjectModelWrapper attribute. The {0} typ
- The {0} cmdlet defines the {1} parameter set more than once.
AI-assisted analysis of PowerShell/PowerShell@3ff3c711bf (2026-08-13).
Data as JSON: /api/errors/5da9d2645f5656c5.
Report an issue: GitHub.