【发布时间】:2014-07-22 22:52:13
【问题描述】:
目前,我的 Mac 上运行着一个用 C# 编写的服务,位于 usr/local/program。该服务能够通过根据服务器版本号检查版本号来检测何时需要更新。更新方法会运行,但是当它尝试下载包含信息和要下载的文件的update.xml 文件时总是会出现异常。这是我们从自定义记录器中得到的异常:
11:09:46 AM [Debug] Exception Type: WebException
11:09:46 AM [Debug] Stack Trace for above:
at System.Net.WebClient.DownloadFile (System.Uri address, System.String fileName) [0x00000] in <filename unknown>:0
at System.Net.WebClient.DownloadFile (System.String address, System.String fileName) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Net.WebClient:DownloadFile (string,string)
at dabler.Client.ClientService.tryUpdate () [0x00000] in <filename unknown>:0
11:09:46 AM [Debug] System.NotSupportedException: http://www.website.com/updates/client/update.xml
at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in <filename unknown>:0
at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in <filename unknown>:0
at System.Net.WebClient.GetWebRequest (System.Uri address) [0x00000] in <filename unknown>:0
at System.Net.WebClient.SetupRequest (System.Uri uri) [0x00000] in <filename unknown>:0
at System.Net.WebClient.DownloadFileCore (System.Uri address, System.String fileName, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.DownloadFile (System.Uri address, System.String fileName) [0x00000] in <filename unknown>:0
我对此进行了研究,根据我找到的文档,NotSupportedException 表示“该方法已在多个线程上同时调用”。但是,这是该服务第一次尝试下载文件,所以我不明白这是怎么发生的。我想到的一种可能性是它正在尝试将文件下载到usr/local/program/update.xml,但我授予了程序对该文件夹的根访问权限。
【问题讨论】:
-
NotSupportedException实际上是从WebRequest.GetCreator抛出的。该方法似乎是特定于 Mono 的,如果找不到 URI 前缀,则会抛出该方法。请参阅github.com/mono/mono/blob/master/mcs/class/System/System.Net/… 的源代码。但不确定为什么会发生这种情况:“http://”对我来说似乎是一个有效的 URI 前缀。 -
@pmcoltrane 目前我在两台计算机上安装了该服务。一台计算机已经安装了 3.2.6 的单声道,而不能运行的计算机包含 3.4.0。就 WebRequest.cs 而言,它们之间有区别吗?
-
我看不到。在做了一些额外的搜索之后,我相信这些问题是相关的:stackoverflow.com/questions/17427255/…stackoverflow.com/questions/17657145/…
标签: c# webclient notsupportedexception