I am trying to parse an XML document returned from this link , but I am getting an exception of type ComException with the following message:
Error HRESULT E_FAIL has been returned from a call to a COM component.
Here is the code:
try { //... string EPGXML = await DownloadAsync(url); var xmldoc = new XmlDocument(); xmldoc.LoadXml(EPGXML); //this line throws the exception //...rest of the code } catch (Exception) { //I get here... }
Could you please help me why I get this message and how can I fix it? Thank.
EDIT:
I am reading the XML source using this function (maybe I'm wrong here, and I have to do something to get the string in UTF-8, because I do not see German characters in the string in debug mode (viewport):
private async static Task<string> DownloadPageAsync(string url) { try { HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; handler.AllowAutoRedirect = true; handler.UseCookies = true; HttpClient client = new HttpClient(handler); client.MaxResponseContentBufferSize = 10000000; HttpResponseMessage response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsString(); return responseBody; } catch (Exception ex) { return "error" + ex.Message; } }
Alireza Noori Nov 30 2018-11-11T00: 00Z
source share