This project has moved and is read-only. For the latest updates, please go here.


"Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'."


The above exception is happening every time I go to update. I tracked it down to the DownloadUpdateDialog method GetFileName( ) at line 67. I'm not intimately familiar with web requests but for some reason what is being generated by that line is a FileWebRequest rather than an HttpWebRequest, which is causing the exception. A seemingly simple fix but the FileWebResponse class doesn't have a status property which is what is driving the next bit of logic.

After reading up on the exception a bit I'm guessing it's because of my update XML. From what I read there should be an HTTP at the beginning of my URI or it's considered to be a file path.

<title>New version is available for XXXXXX</title>
<url>\<<ip address>>\WebData\staging\XXXXXX</url>

If that's not supported, you might just want to reject the XML entirely with a message that explains why it's being rejected.

file attachments


igolets wrote Nov 12, 2014 at 5:27 AM

Please try
<url>\<<ip address>>\WebData\staging\XXXXXX</url>

It works fine for me.

igolets wrote Nov 12, 2014 at 5:29 AM

Sorry, 2 " \ " chars should be at the beginning: \\<<ip address>>

kushalcecypo wrote Dec 20, 2014 at 8:40 AM

Same error suddently after updating to 1.3.1
My uri is; "\\\Users\Public\RaminianUpdates\Raminian Setup.exe"

my actual path is \\users\Public\RaminianUpdates\Raminian Setup.exe
The path and file are valid (they exist).

Error happens in;
DownloadUpdateDialog.cs > GetFileName()
Line: var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
Error Message:
An unhandled exception of type 'System.InvalidCastException' occurred in AutoUpdater.NET.dll

Additional information: Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'.

Please advise how to fix, thanks.

kushalcecypo wrote Dec 20, 2014 at 8:45 AM

Sorry to add onto the above, but does this mean that the latest version does NOT support updating from the LAN/file system, and requires an http:// or ftp:// in the update .XML file?

I'm in a country with extremely slow, and expensive internet speeds, and updating via LAN is definitely preferred.

wrote Dec 20, 2014 at 8:47 AM

kushalcecypo wrote Dec 20, 2014 at 8:47 AM

I made the following change in GetFileName() to get it working for my LAN;
At the top of GetFileName(), and attached:

var fileName = string.Empty;
        var httpWebRequest = (FileWebRequest)WebRequest.Create(url);
        httpWebRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
        httpWebRequest.Method = "HEAD";
        //httpWebRequest.AllowAutoRedirect = false;
        var httpWebResponse = (FileWebResponse)httpWebRequest.GetResponse();
        //if (httpWebResponse.StatusCode.Equals(HttpStatusCode.Redirect) || httpWebResponse.StatusCode.Equals(HttpStatusCode.Moved) || httpWebResponse.StatusCode.Equals(HttpStatusCode.MovedPermanently))
            if (httpWebResponse.Headers["Location"] != null)
                var location = httpWebResponse.Headers["Location"];
                fileName = GetFileName(location);
                return fileName;

wrote Mar 21, 2015 at 6:04 AM

wrote Nov 27 at 6:54 PM