TaskCanceledException: Cannot access a disposed object. Object name: 'MobileAuthenticatedStream'

Finlay Brown 1 Reputation point
2022-08-22T22:25:39.49+00:00

Getting this error on the first app http request when the app starts up. This occurs in both Android and iOS, it does not happen every time and I cannot reliably replicate it, repeating the same request afterwards works correctly.

Object name: 'MobileAuthenticatedStream'.  
at Mono.Net.Security.MobileAuthenticatedStream.StartOperation (Mono.Net.Security.MobileAuthenticatedStream+OperationType type, Mono.Net.Security.AsyncProtocolRequest asyncRequest, System.Threading.CancellationToken cancellationToken) [0x00245] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:410   
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00c5c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs:551   
--- End of inner exception stack trace ---  
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x0129b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs:739   
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x000e6] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:330   
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x00101] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs:296   
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00070] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs:32   
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000d7] in <831b7afb4f024d399aa7f21c2ef99b9c>:0   
at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendCoreAsync (System.Net.Http.HttpRequestMessage request, Polly.Context context, System.Threading.CancellationToken cancellationToken) [0x000dc] in <fdbe77d51f99428cbaad707c9b22e67a>:0   
at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult] (System.Func`3[T1,T2,TResult] action, Polly.Context context, System.Threading.CancellationToken cancellationToken, Polly.ExceptionPredicates shouldRetryExceptionPredicates, Polly.ResultPredicates`1[TResult] shouldRetryResultPredicates, System.Func`5[T1,T2,T3,T4,TResult] onRetryAsync, System.Int32 permittedRetryCount, System.Collections.Generic.IEnumerable`1[T] sleepDurationsEnumerable, System.Func`4[T1,T2,T3,TResult] sleepDurationProvider, System.Boolean continueOnCapturedContext) [0x0012e] in <ab401ba6fe434cfbb0784f458cf3f3ea>:0   
at Polly.AsyncPolicy`1[TResult].ExecuteAsync (System.Func`3[T1,T2,TResult] action, Polly.Context context, System.Threading.CancellationToken cancellationToken, System.Boolean continueOnCapturedContext) [0x0009f] in <ab401ba6fe434cfbb0784f458cf3f3ea>:0   
at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00126] in <fdbe77d51f99428cbaad707c9b22e67a>:0   
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ef] in <831b7afb4f024d399aa7f21c2ef99b9c>:0   
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs:506   
at App.Method`1[T].GetRequestAsync[O] (System.String url, System.Boolean useBackground) [0x0015d] in <9aeb34a0def84b7dbbba21e6fb8b9f0d>:0   

Any solutions or causes of this issue

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,354 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.