Documentation error?

In the HTTP Utils documentation (https://docs.servicestack.net/http-utils#uploading-files) the example on how to upload a file from a stream, shows the following

using (var stream = uploadFile.OpenRead())
{
    var webRes = webReq.UploadFile(stream, uploadFile.Name, MimeTypes.GetMimeType(uploadFile.Name));
}

But the VS2019 compiler throws an error saying that I “Cannot assign void to an implicitly-typed variable”, which seems correct, as the UploadFile method indeed do return void…?

Furthermore, I cant seem to get any response afterwards. The HttpWebRequest’s HaveResponse property is false - even tough Fiddler show the following result:

HTTP/1.1 500 Internal Server Error
Connection: close
Date: Sat, 15 Feb 2020 09:42:41 GMT
Content-Length: 252
Content-Type: application/json;charset=UTF-8
x-responded-by: cors-response-filter
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: origin,accept,content-type,authorization
X-ORACLE-DMS-RID: 0
Set-Cookie: JSESSIONID=6-dIOo5OADvx8NCAaX0ENFqkhlwojyf_Ms5lRd7VUU3Bx9dm91_8!514455225; path=/; HttpOnly
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS,HEAD
X-ORACLE-DMS-ECID: 17a0336a-fd01-46f8-8304-b732fda20e19-0000039a
*Access-Control-Allow-Origin: **

{“errors”:[{“type”:“E”,“text”:“java.nio.file.FileSystemException: \\SRVTTIAFIL01\Applications\ttia5201\TSFA\SRVTTIAFIL01\Applications\ttia5201\TSFA\archive: The user name or password is incorrect.\r\n”,“timestamp”:“2020-02-15T10:42:45.472”}]}

Any ideas?

Yep it doesn’t return anything so the example shouldn’t have a response which I’ve just updated. FYI The “Edit on GitHub” link in the top right of every change with let you send a quick PR update to fix any doc errors.

If the error returned an Error response it should throw a WebException, HTTP Utils also contains some extension methods to help with Exception Handling.

The point is that UploadFile doesn’t return anything OR throw any exception, even though the remote server returns an error and code 500. So how do I get the response, Fiddler shows is there?
This is my code (the service acts as a proxy for a backend webservice).

    public void PostToTIA(string url, ServiceStack.Web.IHttpFile file)
    {
        try
        {
            log.Info(string.Format("TIA REST POST file request: {0}", url));

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Accept = MimeTypes.Json;
            webRequest.AddBasicAuth(_userName, _password);
            webRequest.KeepAlive = true;
            webRequest.UploadFile(file.InputStream, file.FileName, file.ContentType);

            log.Info("TIA REST POST file success");
        }
        catch (WebException wexc)
        {
            ...
        }
    }

I’d take KeepAlive off, as you’re not attempting to reuse a persistent connection.

UploadFile does not swallow the Exception so it should throw, maybe your Proxy is muting it somehow, either way there’s nothing more the library can do, the HttpWebRequest docs says it throws a WebException when errors occur while accessing a resource, I can’t say why it’s not throwing for you, I’ve never heard of an issue where it was not throwing for HTTP Error responses before.