1
おはよう、 PowerShellクラスをV5でテストしており、Powershellクラス内でリフレクションを使用できません。以下の例を見てみましょう:私たちが見ることができるように、私はディレクトリのzipファイルを作成するためにリフレクションを使用した後、アセンブリをロードしていますPowershellクラス内でリフレクションを使用するクラス
class PSHello{
[void] Zip(){
Add-Type -Assembly "System.IO.Compression.FileSystem"
$includeBaseDirectory = $false
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory('C:\test', 'c:\test.zip',$compressionLevel ,$includeBaseDirectory)
}
}
$f = [PSHello]::new()
$f.Zip()
。これが実行されるしかし、ときに私はそれが動作するクラスの外で私の郵便法の同じ内容を実行する場合、私は今
Unable to find type [System.IO.Compression.ZipFile].
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TypeNotFound
のエラーを受け取ります。だから、リフレクションは、このようなクラスの中で使うことができないのはなぜですか?
マイティ興味深いが、簡単な解決策であるかもしれない問題 – jladd
起動式の解答と解説をありがとうございました... – wOxxOm