1

I've been banging my head with this issue since last night. It only happens on the deployed binaries in Windows Server 2012 IIS with no clear error logs. But in Visual Studio, no problem at all.

try
{
    using (var client = new HttpClient())
    {
        var requestUri = "http://[some-vcloud-ipaddress]/api/versions";

        var response = await client.GetAsync(requestUri);           // <-- This is line 94

        if (response.IsSuccessStatusCode)
        {
            var xml = await response.Content.ReadAsStreamAsync();
            var result = Serializer<SupportedVersions>.Deserialize(xml);
            return result;
        }
        return null;
    }
}
catch (Exception ex)
{
    _logger.ErrorFormat("VcloudApiClient - GetSupportedVersions failed. Error message: {0}", ex.Message);

    _logger.ErrorFormat("VcloudApiClient - GetSupportedVersions failed. Error stacktrace: {0}", ex.StackTrace);

    throw;
}

Below is the error log.

VcloudApiClient - GetSupportedVersions failed. Error message: An error occurred while sending the request.

VcloudApiClient - GetSupportedVersions failed. Error stacktrace:    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at SomeProject.Tpl.VcloudDirector.VcloudApiClient.<GetSupportedVersions>d__1.MoveNext() in d:\Projects\SomeProject-01\src\Api\SomeProject.Tpl\VcloudDirector\VcloudApiClient.cs:line 94

Please note that there's no problem executing the URL on any other clients (browsers, Postman REST client, etc.).

Paulo Morgado
  • 14,111
  • 3
  • 31
  • 59
Dennis Laping
  • 682
  • 1
  • 7
  • 18
  • 1
    Is there an InnerException? What does that say? – Tasos K. Nov 29 '15 at 08:41
  • Nope, that is it. I wish I can give you more detailed error message. – Dennis Laping Nov 29 '15 at 10:07
  • 1
    In some cases, setting a user agent string helps. Take a look [here](http://stackoverflow.com/questions/13772937/custom-user-agent-for-httpclient) – Tasos K. Nov 29 '15 at 10:26
  • 1
    Have you tried using [Fiddler](http://www.fiddlertool.com/) to see what goes on the wire? – Paulo Morgado Nov 29 '15 at 12:08
  • 1
    Are you *sure* there's no inner exception? That seems unlikely. Please update your code to loop through the exceptions and post results again. For example `while (ex != null) { //your previous log code; ex = ex.InnerException; }` – Rob Nov 29 '15 at 23:13
  • 1
    For those issues only happen on servers, you can try [remote debugging](https://msdn.microsoft.com/en-us/library/y7f5zaaa(v=vs.110).aspx) – Cheng Chen Nov 30 '15 at 02:33
  • @PauloMorgado, yes, I have tried fiddler and it only returned the dreaded 500 - Internal Server Error. – Dennis Laping Nov 30 '15 at 02:57
  • I will try the remote debugging, the custom user agent and ex.InnerException... Thanks, guys! – Dennis Laping Nov 30 '15 at 02:59
  • Doesn't that tell you that it's a server error? – Paulo Morgado Nov 30 '15 at 07:35
  • I had an same issue this helped me `var response = await client.GetAsync(requestUri).ConfigureAwait(false)` for more information [Check](http://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async). – Aizaz Ahmed Nov 30 '15 at 09:40

0 Answers0