What exception type should be used in Powershell to catch a XML parse error due to invalid characters?

后端 未结 2 791
一向
一向 2021-01-18 08:19

Line 2 in the script below generates -

\"Cannot convert value \"System.Object[]\" to type \"System.Xml.XmlDocument\". Error: \"\'→\', hexadecimal va

相关标签:
2条回答
  • 2021-01-18 09:10

    System.Management.Automation.ArgumentTransformationMetadataException

    0 讨论(0)
  • 2021-01-18 09:21

    Here is a way to discover yourself the full type name of an Exception, the result here gives System.Management.Automation.ArgumentTransformationMetadataException as given by @Adrian Wright.

    Clear-Host
    try {
        [xml]$xml = Get-Content "c:\Temp\1.cs" # line 2
    }
    catch {
        # Discovering the full type name of an exception
        Write-Host $_.Exception.gettype().fullName
        Write-Host $_.Exception.message
    }
    
    0 讨论(0)
提交回复
热议问题