There is an error in one of my Asynchronous methods, but it never returns anything. I thought it would return a Task with a null value. I need it to return something so that I can continue the LoadCollection() method even if there is an error.
The error occurs at the serializer.Deserialize() method. However, this Newtonsoft method doesn't have any Exceptions written for it.
internal async Task LoadCollection(Project activeProject)
{
Collections collections = await HttpClientInstance.DownloadCollectionAsync(activeProject); //never returns anything
if (collections != null) //never hits this line
{
MyCollection = new ObservableCollection<WindowEntity>(collections.Collection.Select(x => x.Material).ToList());
}
return;
}
public static async Task<Collections> DownloadCollectionAsync(Project activeProject)
{
HttpRequestMessage msg = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(HttpClientInstance.BaseUri + "projects/get-collections/")
};
msg.Headers.Add("projectID", $"{activeProject.Id}");
string responseString = null;
using (var response = await httpClient.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
{
if (response.IsSuccessStatusCode)
{
try
{
using (Stream s = await response.Content.ReadAsStreamAsync())
using (StreamReader sr = new StreamReader(s))
using (JsonReader reader = new JsonTextReader(sr))
{
JsonSerializer serializer = new JsonSerializer();
return serializer.Deserialize<Collections>(reader); //error from this deserialization
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
return null;
}
What am I doing wrong with my error handling that causes this LoadCollection() method to never finish?