I was trying to query fundraising pages and I started getting an error that showed as Cannot access a disposed object. After checking the JustGiving client logs, I noticed an Unauthorized error in the logs. Reauthenticating with OAuth and getting a fresh access token fixed the error.
I think the correct error is being thrown but in a catch or finally block, another error is being caused by the HttpClient. This is very confusing for developers when it's really masking a simple issue like an expired token.
Code:
var client = new JustGivingApiClient(ClientId, ClientSecret, new OAuthAccessToken(accessToken));
client.UseProduction();
client.LogEverything();
var logger = new TestLogProvider();
client.LogProvider = logger;
return await client.Fundraising.GetFundraisingPages();
Error:
Cannot access a disposed object.
Object name: 'System.Net.Http.StreamContent'.
at System.Net.Http.HttpContent.CheckDisposed()
at System.Net.Http.HttpContent.ReadAsStringAsync()
at JustGivingSDK.Clients.ClientBase.<Execute>c__async2`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at JustGivingSDK.Clients.Fundraising.FundraisingClient.<GetFundraisingPages>c__async10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MyService.BusinessLogic.JustGivingService.<GetPages>d__8.MoveNext() in C:\code\MyService\BusinessLogic\JustGivingService.cs:line 149
I was trying to query fundraising pages and I started getting an error that showed as
Cannot access a disposed object
. After checking the JustGiving client logs, I noticed an Unauthorized error in the logs. Reauthenticating with OAuth and getting a fresh access token fixed the error.I think the correct error is being thrown but in a
catch
orfinally
block, another error is being caused by theHttpClient
. This is very confusing for developers when it's really masking a simple issue like an expired token.Code:
Error:
Logs from JustGiving client: