当运行以下命令来创建HtmlDocument实例时,在最后一行会引发一个对象不匹配异常
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "GET";
request.Timeout = 5000;//stop trying after 5s
WebResponse response = request.GetResponse();
HtmlDocument doc = new HtmlDocument();
doc.OptionReadEncoding = false;
doc.Load(response.GetResponseStream());
引发的异常显示为“类型为‘NInterpret.ExplationObject’的对象与目标类型‘System.Collections.Generic.IEnumerable’1[NInterpretedObject]’不匹配”
尝试从字符串加载html时会引发相同的错误,例如:
HtmlDocument doc = new HtmlDocument();
doc.OptionReadEncoding = false;
doc.LoadHtml("<html><head><title>a page</title></head><body>some content</body></html>");
只有通过Xamarin Live Player应用程序运行应用程序时才会发生这种情况,如果应用程序被编译为APK并直接安装到设备上然后运行,则不会发生这种情况。