无法转换'system; _ComObject'类型的COM对象 [英] Unable to cast COM object of type 'system;_ComObject'
问题描述
所以我要做的是从互联网上下载一个zip文件然后解压缩它,它在我的电脑上完美运行但是当我在我的另一台电脑上尝试它时它只是说这个警告:未处理的exeption已经发生在你的应用。如果你单击继续,应用程序将忽略此错误等然后它说无法将类型'system; _ComObject'的COM对象转换为接口类型Shell32.Shell,它继续这样,我真的需要快速解决这个问题,请帮助我?
这是我提取zip文件的代码
So what i am trying to do is download a zip file from the internet and then extract it, it works perfectly on my computer but when i try it on my other computer it just says this warning: Unhandled exeption has occured in your application. If you click continue, the application will ignore this error etc then it says Unable to cast COM object of type 'system;_ComObject' to interface type "Shell32.Shell" and it goes on like that, i really need to fix this quickly, pls help me?
This is my code to extract the zip file
Dim path As String = Directory.GetCurrentDirectory()
Dim sc As New Shell32.Shell()
IO.Directory.CreateDirectory(path & "\extract")
Dim output As Shell32.Folder = sc.NameSpace(path & "\extract")
Dim input As Shell32.Folder = sc.NameSpace(path & "\mods.zip")
output.CopyHere(input.Items, 4)
推荐答案
假设您使用的是.NET 4.5,则可以使用内置ZipFile
类 [ ^ ]。
添加对系统的引用.IO.Compression.FileSystem
程序集,导入
System.IO.Compression
名称空间。然后使用:
Assuming you're using .NET 4.5, you can use the built-inZipFile
class[^].
Add a reference to theSystem.IO.Compression.FileSystem
assembly, andImport
theSystem.IO.Compression
namespace. Then use:
Dim path As String = IO.Directory.GetCurrentDirectory()
Dim zipPath As String = IO.Path.Combine(path, "mods.zip")
If Not IO.File.Exists(zipPath) Then
Throw New IO.FileNotFoundException(Nothing, zipPath)
End If
Dim extractPath As String = IO.Path.Combine(path, "extract")
If Not IO.Directory.Exists(extractPath) Then
IO.Directory.CreateDirectory(extractPath)
End If
ZipFile.ExtractToDirectory(zipPath, extractPath)
如果您使用的是.NET 4.0或更早版本,则可以使用第三方库,例如SharpZipLib [ ^ ]或 DotNetZip [ ^ ]提取文件。
If you're using .NET 4.0 or earlier, then you can use a third-party library such as SharpZipLib[^] or DotNetZip[^] to extract the file.
如何使用该zipfile类?
How can i do use that zipfile class?
这篇关于无法转换'system; _ComObject'类型的COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!