[英]Xamarin Android httpwebrequest, Cannot access a disposed object
[英]Xamarin Cannot access a disposed object
我有一個主詳細信息頁面,在我的菜單上單擊它以導航到其他頁面時,出現此錯誤:
System.ObjectDisposedException:“無法訪問已處置的 object。Object 名稱:‘Android.Renderscripts.RenderScript’。”
但是,只有在我調用這段代碼時才會發生:
protected override async void OnAppearing()
{
await LoadContent();
}
如果我不調用 LoadContent function,菜單工作正常並且我能夠導航到其他頁面。
我的 LoadContent 代碼:
public async Task<firstContentJson> LoadContent()
{
string connectionUrl = "https://myurl.com/app/getcontent.php";
object userInfos = new { };
var jsonObj = JsonConvert.SerializeObject(userInfos);
using (HttpClient client = new HttpClient())
{
StringContent content = new StringContent(jsonObj.ToString(), Encoding.UTF8, "application/json");
var request = new HttpRequestMessage()
{
RequestUri = new Uri(connectionUrl),
Method = HttpMethod.Post,
Content = content
};
var response = await client.SendAsync(request);
string dataResult = response.Content.ReadAsStringAsync().Result;
firstContentJson result = JsonConvert.DeserializeObject<firstContentJson>(dataResult);
try
{
string contentid = JObject.Parse(dataResult)["content_id"].ToString();
string rep = JObject.Parse(dataResult)["rep"].ToString();
string creator = JObject.Parse(dataResult)["creator"].ToString();
string text = JObject.Parse(dataResult)["text"].ToString();
string img = JObject.Parse(dataResult)["img"].ToString();
string totalrate = JObject.Parse(dataResult)["totalrate"].ToString();
//string vid = JObject.Parse(dataResult)["vid"].ToString();
string date = JObject.Parse(dataResult)["date"].ToString();
string name = JObject.Parse(dataResult)["name"].ToString();
string pic = JObject.Parse(dataResult)["pic"].ToString();
string visits = JObject.Parse(dataResult)["visits"].ToString();
string lvl = JObject.Parse(dataResult)["lvl"].ToString();
//inicio load first content
imgTop.Source = "https://myurl.com/" + img;
avUser.Source = "https://myurl.com/" + pic;
txtName.Text = "@"+name;
txtDesc.Text = text;
imgContent.Source = "https://myurl.com/" + img;
txtRate.Text = rep;
if(Convert.ToInt32(totalrate)>0)
{
txtInfos.Text = "Avaliado por " + totalrate + " pessoas";
}
else
{
txtInfos.Text = "Seja o primeiro a avaliar esse conteúdo!";
}
indload.IsVisible = false;
indload.IsRunning = false;
}
catch
{
indload.IsVisible = false;
indload.IsRunning = false;
}
return result;
}
}
有人可以幫助我嗎?
編輯:當我點擊菜單時的錯誤圖片
解決方案:問題出在一個名為 Sharpnado.Shadows 的插件上。 我將它從我的母版頁中刪除,一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.