Исключение в приложении .Net MAUI: «System.ObjectDisposeException: невозможно получить доступ к закрытому потоку» на AndC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Исключение в приложении .Net MAUI: «System.ObjectDisposeException: невозможно получить доступ к закрытому потоку» на And

Сообщение Anonymous »


I am currently developing a .Net MAUI application where I am making an HTTP call using a specific function. The peculiar issue I am facing is that the function works perfectly fine on Windows, but when I attempt to execute it on Android, it throws an exception:

"System.ObjectDisposedException: Cannot access a closed Stream."

public async static Task InsertParts(IEnumerable partsToReport) { using (HttpClient client = GetClient()) { AddAuthorizationHeader(client); string url = $"{Url}/endpoint"; string jsonData = JsonSerializer.Serialize(partsToReport); HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); if (!(response.IsSuccessStatusCode)) { throw new Exception($"Failed to insert parts: {response.ReasonPhrase}"); } } } public static HttpClient GetClient() { #if DEBUG HttpClientHandler insecureHandler = new HttpClientHandler(); insecureHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; return new HttpClient(insecureHandler); #else return new HttpClient(); #endif } GET and DELETE works on both platforms

The Post operation like this works on both platforms

HttpResponseMessage response = await client.PostAsync($"{Url}/inventory/{id}/{destination}", null);

but when I try to put content in the request then it does not work on android but works in Windows.


Источник: https://stackoverflow.com/questions/772 ... cess-a-clo
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»