thomasgalliker / OpenWeatherMap.API

OpenWeatherMap API client for .NET
1 stars 1 forks source link

Culture name is not supported #15

Closed JW-CH closed 1 week ago

JW-CH commented 1 week ago

I am getting following exception when trying to use your nuget with a asp.net core webapi. I am from switzerland and the Culture name CH (de-CH) should be correct. Not sure why this crashes.

System.ArgumentException: Culture name 'CH' is not supported. (Parameter 'name')
          at System.Globalization.RegionInfo..ctor(String name)
          at OpenWeatherMap.Models.Converters.RegionInfoJsonConverter.ReadJson(JsonReader reader, Type objectType, RegionInfo existingValue, Boolean hasExistingValue, JsonSerializer serializer)
          at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
          at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
          at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
          at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
          at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
          at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (String value, JsonSerializerSettings settings)
          at OpenWeatherMap.OpenWeatherMapJsonSerializer.DeserializeObject[T] (String value)
          at OpenWeatherMap.OpenWeatherMapService.GetCurrentWeatherAsync(Double latitude, Double longitude)
JW-CH commented 1 week ago

For more context, I am running this inside a docker container. (.net 8.0)

thomasgalliker commented 1 week ago

First of all: yeah, thanks for using this plugin. If you're from Switzerland, I would highly recommend the nuget MeteoSwissApi, as it provides more acurate weather data and forecasts for Switzerland.

Regarding the problem: What OpenWeatherMap configuration do you use? (Don't paste your Openweathermap API key here :))

JW-CH commented 1 week ago

First of all: yeah, thanks for using this plugin. If you're from Switzerland, I would highly recommend the nuget MeteoSwissApi, as it provides more acurate weather data and forecasts for Switzerland.

Regarding the problem: What OpenWeatherMap configuration do you use? (Don't paste your Openweathermap API key here :))

I think I was a bit fast with creating an issue. I am not using swiss-only weather data, that's why Openweathermap fits my needs.

I managed to resolve my issue. I was using the .net 8.0-alpine docker base image which is not shipped with full globalization support (see here).

I am not quite sure why only this nuget caused this issue since I am calling other APIs too. Closing this as it is not really related to your project.

thomasgalliker commented 1 week ago

If you set the option "VerboseLogging" to true, you can see the JSON content returned by OpenWeatherMap. Would be interesting to see what the content the response is.

Mine looks like this:

{"coord":{"lon":8.4606,"lat":47.1815},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"stations","main":{"temp":15.58,"feels_like":15.49,"temp_min":14.74,"temp_max":16.47,"pressure":1015,"humidity":88,"sea_level":1015,"grnd_level":944},"visibility":10000,"wind":{"speed":1.54,"deg":210},"rain":{"1h":0.15},"clouds":{"all":100},"dt":1729257609,"sys":{"type":1,"id":6933,"country":"CH","sunrise":1729230531,"sunset":1729269199},"timezone":7200,"id":2661228,"name":"Cham","cod":200}
thomasgalliker commented 1 week ago

Oops! Ok, never heard of something like this. If you see other bugs or potential for extensions... let me know. Just create a new issue. Have a good day!