我使用SevenZipSharp库生成了一个多卷7z文件。
我遇到的问题是,当我尝试提取文件时,出现关于无效转换的异常:
无法投射物体
类型为“SevenZip.InMultiStreamWrapper”的类型为“SevenZip.InStreamWrapper”。
抛出异常的方法是SevenZipExtractor.Check()
。
这是用 Vb.Net 编写的用于重现提取问题的示例代码,但我也可以接受 C# 解决方案:
Public Overridable Function Extract(ByVal sourceFilePath As String,
ByVal outputDirectorypath As String,
ByVal password As String) As String
If String.IsNullOrEmpty(password) Then
Me.extractor = New SevenZipExtractor(sourceFilePath)
Else
Me.extractor = New SevenZipExtractor(sourceFilePath, password)
End If
' Check for password matches doing an integrity check.
If Me.extractor.Check() Then
' Start the extraction.
Me.extractor.ExtractArchive(outputDirectorypath)
Else
Throw New Exception(
"Failed to extract, maybe the provided password does not match?.")
End If
Return outputDirectorypath
End Function
如果我忽略完整性检查,使用设置了密码的多卷文件,那么我无法提取它,因为发生另一个异常......
可能是他们源代码中的一个错误,但我要求确定,因为库不支持提取多卷文件很奇怪......