简体   繁体   English

Xamarin 无法访问已处置的 object

[英]Xamarin Cannot access a disposed object

i have a master detail page, on my menu when i click on it to navigate to other page, i got this error:我有一个主详细信息页面,在我的菜单上单击它以导航到其他页面时,出现此错误:

System.ObjectDisposedException: 'Cannot access a disposed object. Object name: 'Android.Renderscripts.RenderScript'.' System.ObjectDisposedException:“无法访问已处置的 object。Object 名称:‘Android.Renderscripts.RenderScript’。”

BUT , it only happen when i'm calling this code:但是,只有在我调用这段代码时才会发生:

    protected override async void OnAppearing()
    {
        await LoadContent();
    }

If i don't call the LoadContent function, the menu works fine and i'm able to navigate to other pages.如果我不调用 LoadContent function,菜单工作正常并且我能够导航到其他页面。

My LoadContent code:我的 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;
        }
    }

Someone can help me, please?有人可以帮助我吗?

EDIT: Picture of the error when i click on the menu编辑:当我点击菜单时的错误图片

Solution: the problem was a plugin called Sharpnado.Shadows.解决方案:问题出在一个名为 Sharpnado.Shadows 的插件上。 I removed it from my Master page and everything is working fine again.我将它从我的母版页中删除,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM