我正在尝试向我的profile.ps1添加一些代码,使我能够与一些充满xml文件的zip文件进行交互。我可以在shell中手动完成此操作,并且读取过程不需要帮助,但它在我的profile.ps1中不起作用。
Add-Type -AssemblyName "System.IO.Compression","System.IO.Compression.FileSystem"
class DataPair
{
[System.IO.Compression.ZipArchive]$archive
[System.Xml.XmlDocument]$xmldoc
}这是在我的profile.ps1的最顶部,所以我可以与命名的存档和xml文档共享一个DataPair对象,因为一些帮助函数引用了原始存档中的其他xml。
当我在命令提示符shell或打开Powershell ISE中加载它时,我收到此错误。
At C:\Users\rrobertson\Documents\WindowsPowerShell\profile.ps1:5 char:6
+ [System.IO.Compression.ZipArchive]$archive
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.IO.Compression.ZipArchive].
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TypeNotFound如何修复此引用?或者,是否有一个非类选项可以让我以一种简单的引用格式将这两个值存储在一起?
发布于 2019-02-12 03:05:16
显然,这是Powershell解析器中的一个已知错误。解析器不读取由Add-Type或using assembly加载的程序集,但是我能够通过使用[System.IO.Compression.ZipArchive, System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKey=b77a5c561934e089]中的完全程序集限定类型名来满足解析器的要求。
这还会将程序集添加到AppDomain中,因此它是目前的一种解决方法。
https://stackoverflow.com/questions/54599963
复制相似问题