将项目添加到列表时"Attempted to read or write protected memory."<>



遇到奇怪的错误。少量研究表明,当你篡改代码中的内存时,就会出现这种错误。我不做这种事。

完全错误:

Cineman.ni.DLL 中发生类型为"System.AccessViolationException"的未处理异常

附加信息:试图读取或写入受保护的内存。这通常表示其他内存已损坏。

没有可用的堆栈跟踪。

这里有一些代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cineman.ViewModels
{
public class AirTime
{
public string Time { get; set; }
}
}

发生错误的代码:

public List<AirTime> AirTimes { get; set; }
public async Task<bool> GetDetailsAsync()
{
if (this.Year == null)
{
this.IsDetailsLoaded = "visible";
Uri uri = new Uri(this.DetailsUrl);
HttpClient client = new HttpClient();
HtmlDocument htmlDocument = new HtmlDocument();
HtmlNode htmlNode = new HtmlNode(0, htmlDocument, 1);
MovieData Item = new MovieData();
string HtmlResult;
try
{
HtmlRequest = await client.GetAsync(uri, _cts.Token);
HtmlResult = await HtmlRequest.Content.ReadAsStringAsync();
}
if (!(HtmlResult == null) && HtmlRequest.IsSuccessStatusCode)
{
await this.DownloadPosterAsync();
htmlDocument.LoadHtml(HtmlResult);
this.LargePoster = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='cinema_img']/a").GetAttributeValue("href", "No poster image");
await this.DownloadLargePosterAsync();
htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='sessions_day']/table/tbody");
if (this.Today)
{
foreach (var child in htmlNode.ChildNodes)
{
var time = new AirTime();
//time.Time = DateTime.Parse(child.SelectSingleNode("td[1]").InnerText);
time.Time = child.SelectSingleNode("td[1]").InnerText;
this.AirTimes.Add(time); //Error fires up here
//this.AirTimeText += child.SelectSingleNode("td[1]").InnerText + "  ";
} 
}
this.IsDetailsLoaded = "Collapsed";
}
}
return true;
}

到目前为止我尝试了什么:
1。我删除了类和属性,然后重新创建。运气不好
2.我评论了一个引发错误的代码,"一切正常">
3.我取消了JIT优化。没有帮助
4.我检查了所有变量,它们都不为空,所有类型转换都到位
5。阅读大量关于这方面的文章和帖子:)
6。我甚至重新启动了电脑、手机,删除了隔离存储,试图在手机上部署发布包而不是调试
我没有尝试在模拟器上启动应用程序,因为我有Win 8,无法访问我的桌面。

这不是公共财产吗?

public List<AirTime> AirTimes { get; set; }

创建一个类变量并实例化它:

private List<AirTime> mobjAirTimes = new List<AirTime>;

然后从你的财产中归还。

public List<AirTime> AirTimes
{
get 
{
return mobjAirTimes ; 
}
set 
{
mobjAirTimes = value; 
}
}

相关内容

最新更新