【发布时间】:2021-02-05 16:08:09
【问题描述】:
我创建了一个小的 VB.NET 控制台应用程序(使用 Visual Studio 2019 社区版),它会自动从 Internet 下载文件。
如果我从项目树中的 Debug 目录启动已编译的 .exe,它就可以正常工作;如果我将应用程序发布到本地文件夹,则不会;相反,我收到错误消息:
Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
这是我用来发布我的应用程序的配置:
显然,这是产生异常的代码:
在程序模块中:
Imports System
Imports Microsoft.VisualBasic
Imports Microsoft.Win32
Module Program
Sub Main(Args() As String)
(...)
End Sub
Sub Download_SpeedTest()
Dim ooklaWebSite As String
Dim html As String
ooklaWebSite = "https://www.speedtest.net/apps/cli"
Try
' Retrieve download link
Console.WriteLine("Getting download link from " & ooklaWebSite)
html = Get_WebPage(ooklaWebSite)
(...)
Catch ex As Exception
Console.WriteLine("An error occurred downloading SpeedTest utility. - " & ex.Message)
End Try
End Sub
在 WebRequests 模块中:
Imports System.Net
Module WebRequests
Public Function Get_WebPage(WebURL As String) As String
Dim sourceString As String
Dim wc As New System.Net.WebClient
sourceString = wc.DownloadString(WebURL)
wc.Dispose()
Return sourceString
End Function
End Module
这是我从 Windows 命令行运行已发布程序时得到的示例:
Getting download link from https://www.speedtest.net/apps/cli
An error occurred downloading SpeedTest utility. - Could not load type 'System.ComponentModel.AsyncCompletedEventArgs' from assembly 'System.Net.WebHeaderCollection, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
据我所知,只要调用函数Get_WebPage 就会发生异常(其中没有执行任何代码)
有什么建议吗?
【问题讨论】: