vb.net - 使用 WebClient 下载在 mscorlib.dll 中发生抛出错误“System.Reflection.TargetInvocationException”
问题描述
我正在尝试使用以下代码从 url 下载文件:
Private Sub getPatch()
Using client As New WebClient
Dim url As String = My.Settings.host & "/update.zip"
If Directory.Exists(Replace(fName, "\update.zip", "")) Then Directory.Delete(Replace(fName, "\update.zip", ""), True)
Directory.CreateDirectory(Replace(fName, "\update.zip", ""))
AddHandler client.DownloadProgressChanged, AddressOf ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCompleted
client.DownloadFileAsync(New Uri(url), fName)
End Using
End Sub
Public Sub ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Try
If e.ProgressPercentage = 100 Then Exit Sub
ProgressBar1.Value = e.ProgressPercentage
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.Net.DownloadDataCompletedEventArgs)
If Not e.Cancelled AndAlso e.Error Is Nothing Then
MessageBox.Show("Download success")
extractZip(fName)
Else
MessageBox.Show("Download failed")
End If
End Sub
每当下载完成(文件成功保存到我的驱动器),它总是抛出错误
mscorlib.dll 中发生了“System.Reflection.TargetInvocationException”类型的未处理异常附加信息:调用目标引发了异常。
我尝试调试它,但它从不触发 DownloadComplete 方法。
解决方案
推荐阅读
- python-3.x - 如何使用带有 Python 3.7 的 sqlite3 python 模块的 FTS5 扩展?
- javascript - 无法连接到数据库,因为 axios 在 UI javascript 文件中
- prolog - 如何通过指定它应该具有的参数数量来获取谓词?
- database - 当我在持久性 xml 中提供另一个端口 5432 时,连接到端口 1,527 上的服务器 localhost 时出错
- javascript - 遍历对象列表以收集信息,同时计算平均值
- c# - 是否应该为异步委托分配单独的事件?
- sql - 选择 SQL 键类型时的最佳实践
- php - Laravel add 计算值在另一个表中的总和
- python - 如果输入在 if 语句中留空,则中断
- c - 根据二维字符数组中字符串中子字符串的计数调整输出