I'm calling a method to get and parse a JSON from a URL. The code structure is as follows:
internal static void CheckIfSettingsExists()
{
settingsContainer.Values["ApplicationXCurrentVersion"] = Controller.GetCurrentVersionAsync();
}
and the GetCurrentVersionAsync()
function:
internal static async Task<string> GetCurrentVersionAsync()
{
string temp = null;
using HttpClient client = new HttpClient();
try
{
temp = await client.GetStringAsync("https://someurl.cloud.io/api/v4/VersionCheck");
}
catch (Exception e)
{
App.log.Error("Error fetching version check json from API. Exception raised was: " + e.ToString());
return temp;
}
App.log.Info("Successfully got return for VersionCheck");
if (temp == null)
{
return temp;
}
dynamic JsonObj = JsonConvert.DeserializeObject<dynamic>(temp);
return JsonObj["LatestVersion"].ToString();
}
When I was trying to debug what's happening, I saw that after program runs the line temp = await client.GetStringAsync("https://someurl.cloud.io/api/v4/VersionCheck");
instead of executing the catch
block, System.ArgumentException: 'The parameter is incorrect.'
is thrown at the line that is calling the GetCurrentVersionAsync()
(line 3 in the CheckIfSettingsExists()
). I don't understand why this is thrown as even if there was an issue with GetStringAsync()
function, I already have it in try
block. Can someone shine a light for me why this is happening?