ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 6 forks source link

PostFilesWithRequest hides real error behind System.IndexOutOfRangeException #713

Closed edwardgoran closed 4 years ago

edwardgoran commented 4 years ago

Hi, when sending PostFilesWithRequest that will fail and cause an exception, System.IndexOutOfRangeException hides the real exception. I.e. the URL may not exist or the server is not online.

This issue is reproducable. A code snippet below illustrates this.

    class Program
    {
        static void Main(string[] args)
        {
            var client = new JsonServiceClient(); 

            var st = new MemoryStream();
            var uploadFiles = new UploadFile("st", st).InArray();
            client.PostFilesWithRequest<object>("http://doesnotexist", new Req(), uploadFiles);
        }
    }

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' This exception was originally thrown at this call stack: ServiceStack.ServiceClientBase.PostFilesWithRequest(string, object, ServiceStack.UploadFile[]) ServiceStack.ServiceClientBase.PostFilesWithRequest(string, object, System.Collections.Generic.IEnumerable) in ServiceClientBase.cs PostFilesWithRequestError.Program.Main(string[]) in Program.cs

Found in ServiceStack 5.5.0 Replicated in ServiceStack 5.8.0 .NET framework version 4.7.2

The problem appears to be in: https://github.com/ServiceStack/ServiceStack/blob/eb19fd4877ce08dc1390dfcdf3a11921210393b5/src/ServiceStack.Client/ServiceClientBase.cs#L1700

Thanks.

mythz commented 4 years ago

Interesting, .NET Core's WebRequest implementation has different behavior than .NET Framework's which throws System.Net.WebException : The remote name could not be resolved, with this fix, .NET Core now also throws System.Net.WebException : No such host is known No such host is known.

This change is available from the latest v5.8.1 that's now available on MyGet.

thx for reporting!