jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.16k stars 249 forks source link

NullReferenceException while calling CQ.Create() #207

Open Israel4Ever opened 8 years ago

Israel4Ever commented 8 years ago

Hi, I'm calling this code:

CQ dom = CQ.Create(
        duplicatedResult.StreamToFile,
        encoding,
        HtmlParsingMode.Auto,
        HtmlParsingOptions.IgnoreComments
    );

The stream of the file (duplicatedResult.StreamToFile) is the downloaded URL: http://docsouth.unc.edu/fpn/green/green.html

and getting back this exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at CsQuery.HtmlParser.ElementFactory.Parse(Stream inputStream, Encoding encoding)
   at CsQuery.CQ.CreateNew(CQ target, Stream html, Encoding encoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at ***.LogicLayers.Sources.HtmlSource.WebPageDocument.<>c__DisplayClass6_0.b__0() in C:\TFS\***\Development\LogicLayer\ContentDOM\HtmlModel\WebPageDocument.cs:line 134
   --- End of inner exception stack trace ---
   at ***.LogicLayers.Sources.HtmlSource.WebPageDocument.LoadDocument(Uri URL, DownloadingResult duplicatedResult, Encoding encoding) in C:\TFS\***\Development\LogicLayer\ContentDOM\HtmlModel\WebPageDocument.cs:line 149
   at ***.LogicLayers.Sources.HtmlSource.WebPageDocument..ctor(Uri URL, DownloadingResult dr) in C:\TFS\***\Development\LogicLayer\ContentDOM\HtmlModel\WebPageDocument.cs:line 44
   at ***.LogicLayer.BL.DocumentTypes.WebDocument..ctor(DownloadingResult dr) in C:\TFS\***\Development\LogicLayer\BL\DocumentTypes\WebDocument.cs:line 23
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at ***.LogicLayer.BL.DocumentTypes.WebDocument..ctor(DownloadingResult dr) in C:\TFS\***\Development\LogicLayer\BL\DocumentTypes\WebDocument.cs:line 31
   at ***.LogicLayer.BL.DocumentTypes.DocumentsFactory.Get(Uri url, Boolean hideAgent, eFileType[] allowedTypes) in C:\TFS\***\Development\LogicLayer\BL\DocumentTypes\DocumentsFactory.cs:line 35
   at ***.LogicLayer.SearchEngine.Results.TextualResultRecord.ParseUrl() in C:\TFS\***\Development\LogicLayer\SearchEngine\Results\TextualResultRecord.cs:line 34

Any tip for solving this?

Thanks.