0

I am having an error when excecuting a netcore WebApi aplication, the weird thing is that it does run ok on another machine.

Here is the console information when I call the method that causes the error:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 1640.1033ms 200
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:5000/api/weather/provider/1/latitude/37.8267/longitude/-122.423
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method WeatherServices.Controllers.WeatherController.Get (WeatherServices) with arguments (1, 37.8267, -122.423) - ModelState is Valid 
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HKTG39DAMIHF": An unhandled exception was thrown by the application.
System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.) ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at WeatherServices.WeatherApiWrappers.Wunderground.Wunderground.<GetLocalWeather>d__6.MoveNext() in C:\Workspace\ChathamWeatherAPI\WeatherServices\WeatherApiWrappers\Wunderground\Wunderground.cs:line 37
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at WeatherServices.Controllers.WeatherController.Get(Int32 source, String latitude, String longitude) in C:\Workspace\ChathamWeatherAPI\WeatherServices\Controllers\WeatherController.cs:line 50
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
---> (Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object.
   at WeatherServices.WeatherApiWrappers.Wunderground.Wunderground.<GetLocalWeather>d__6.MoveNext() in C:\Workspace\ChathamWeatherAPI\WeatherServices\WeatherApiWrappers\Wunderground\Wunderground.cs:line 37<---

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 526.1252ms 200

From that it seems the error has to do with one of the async methods of the program, but I don't get why, and why it would work on another machine.

project.json:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.Extensions.Caching.Memory": "1.0.0-*",
    "RestClientHelper": "1.0.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "tooling": {
    "defaultNamespace": "WeatherServices"
  }
}

Method that triggers the error, the error happens on the return statement:

    public async Task<IList<Forecast>> GetLocalWeather(double latitude, double longitude)
    {
        var url = $"http://{Domain}/api/{ApiKey}/forecast10day/q/{latitude},{longitude}.json";
        var result = await _restApiCaller.CallListEndPoint(url);

        //Limit the query to 8 days
        return result.Forecast.Txt_Forecast.ForecastDay.Where(day => day.Period < 16)
            .Select(day => day.MapToForecast()).ToList();
    }
Jorge A.
  • 55
  • 1
  • 8
  • Just saw that Omnisharp had this message aswell: An unhandled exception has occurred: Must be able aggregate the response to spread them out across all plugins for /updatebuffer – Jorge A. Jul 19 '16 at 22:41
  • Have you debugged it? It's telling you that something is null - set a breakpoint on line 37 and see what's null. – Brad Jul 19 '16 at 23:30
  • For some reason, the vs2015 installer crashes on the machine with the problem, and Rider doesn't hit the breakpoints, so I wasn't able to. But ... yesterday I managed to kindof reproduce the error on the machine were it was working ok, and fixed it (this one does have vs2015). I will try the fix on the machine where the error was happening and post here if it worked. – Jorge A. Jul 20 '16 at 14:28
  • Ok, I've managed to avoid the thrown error, but it still is working inconsistently. the program builds a query and does a get request with it, on the machine with the problem all the requests are returning null objects, while on the machine without the issue, the same queries return data. I'll close this question since it is to be a different issue. – Jorge A. Jul 20 '16 at 15:40

1 Answers1

0

UPDATE

Ok finally found the issue, it had to do with culture, there were some doubles in the query that (for reasons I'm still not clear since my culture does have the correct format), where using ',' instead of '.' for the decimal separator.

Using a culture invariant string conversion solved the issue

ORIGINAL ANSWER

The error was happening because after calling a get request, the result was a null object, I've checked for nulls before working on the object, and that solved that issue.

The thing is, that this is pointing to a different problem, the exact same request does return data on another machine, still haven't found why.

Jorge A.
  • 55
  • 1
  • 8