0
列挙値のErrorRecord.CategoryInfo.Category
に基づいてエラーを処理しようとしています。PowerShellのErrorRecord.CategoryInfo.Categoryをテストします。
コード:コードではなくdefault
スイッチで、ErrorCategory.InvalidType
スイッチを実行していないのはなぜ
try {
# assembly not installed on workstation
[Reflection.Assembly]::LoadWithPartialName('Oracle.DataAccess')
# throws error with a category of 'InvalidType'
$connection = New-Object Oracle.DataAccess.Client.OracleConnection($ConnectionString)
$Connection.Open()
}
catch {
# generates 'DEBUG: CategoryInfo.Category: InvalidType'
write-debug "CategoryInfo.Category: $($_.CategoryInfo.Category)"
# generates 'DEBUG: Category: InvalidType' (the `default` switch)
switch ($_.CategoryInfo.Category) {
[ErrorCategory.InvalidType] {Write-Debug "InvalidType"}
[ErrorCategory.InvalidOperation] {Write-Debug "InvalidOperation"}
default { write-Debug "Category: $($_.CategoryInfo.Category)" }
}
}
?
Referencing system.management.automation.dll in Visual Studioに受け入れられる回答は、system.management.automation
アセンブリをインストールする必要があることを示唆しています。
このアセンブリをインストールしなくても$_.CategoryInfo.Category
をテストする方法はありますか?
リンクされた質問がどのように関連しているかわかりません。 'System.Management.Automation.dll'はPowerShellの中核です。 PowerShellをC#/ VbScriptで使用するには、参照する必要があります。 –