HTML Linq with HtmlAgilityPack, or alternative, in PCL

.net c# html-agility-pack portable-class-library windows-phone-8

Question

I have written a project on .NET 4 and am currently in the process of allowing it to run on Windows Phone as well. I am using HtmlAgilityPack, a well known library which allows Linq queries over HTML, and am only using the LoadHtml and Linq interfaces it provides.

Having converted the class libraries from .NET 4 to PCL (Portable Class Library) with support for .NET 4 and WP8, I cannot seem to use the HtmlAgilityPack library anymore. Is there a way to allow HtmlAgilityPack to function correctly under a PCL project or is there a variable alternative with a similar Linq interface that does work as intended?

EDIT: HtmlAgilityPack provides 9 different versions, none of which are compatible with PCL. None of them resolve dependencies from the references. For some versions, it may appear that it does but upon usage an error will be thrown with the usual 'cannot load, unresolved dependencies'.

EDIT #2 Since it easy to miss a small comment, I'll update this answer with the solution I came up with. I extracted what was needed for basic functionality and implemented the missing components to make everything work. The result is here https://github.com/Deathspike/HtmlAgilityPack-PCL

Accepted Answer

You've asked and answered your own question - haven't you?

The HtmlAgilityPack does not support use with Portable Class Libraries.

At best you'll need to look at porting/migrating the specific functionality you require in a way that will work on the platforms you are using.


Popular Answer

One option is to port the HTML Agility Pack source code to a PCL. You can run the PCL Compliance Analyzer over it to get an idea of how hard this will be.

Alternatively, use the abstraction pattern. Create a portable interface for the functionality you need (ie LoadHtml and Linq), and then implement that interface for each platform by calling into the HTML Agility Pack. Then your portable code can depend on the platform-specific implementation.

For more information, see this blog post: How to Make Portable Class Libraries Work for You




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why