System.XML.XPATH error

Jan 18, 2013 at 9:01 PM

Getting an Exception when using the NavigationService to go to the About page

"Could not load file or assembly 'System.Xml.XPath, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

here's the code:

        private void about_Click(object sender, EventArgs e)

    NavigationService.Navigate(new Uri("/YourLastAboutDialog;component/AboutPage.xaml", UriKind.Relative));


Downloaded YLAD from nuget.

Jan 20, 2013 at 8:39 AM

Hi jangooni,

do you have a sample project that shows this error? Or at least provide more information on your setup?

I just tried creating new projects for Windows Phone 7 and 8, adding the YLAD NuGet package and your code - works without a problem.


Feb 2, 2013 at 12:21 PM

I have the same problem, and a sample project with the error.

You can find the sample here:

To explain what is happening:
1) Add YLAD - works OK
2) Add HTMLAgility Pack - needs System.XML.Xpath to compile
3) We add the reference to: C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Xml.XPath.dll
4) Project compiles but the sample doesn't work.

The problem seems to be with the XPath dll. Also, need to mentions: this bug is only on Windows Phone 8. On WP 7 it works just fine. My app in store: uses YLAD and XPath + Agility Pack. If you run the app in WP 7 (7.5) and go to about page (YLAD) it works. On WP 8 it doesn't.

Feb 2, 2013 at 7:00 PM
Hi Timo,

first of all thank you for the additional information that finally allowed me to reproduce the problem. Here is the result of my investigation.

Short answer: XPath is not supported on the phone. If you want to use HTML Agility Pack, use the LinqToXml features instead.

Long version:

Enabling the XPath features on Windows Phone only works, as you stated, when you add a reference to the System.Xml.XPath assembly of the Silverlight 4 SDK. This is considered an unsupported workaround to add XPath support to Windows Phone which worked in the past on 7.x (also note the warning you receive in Visual Studio when you add the reference, about unexpected behavior). In Windows Phone 8, this trick doesn't seem to work anymore (see also Mathias comment here, for example).

Apparently there now is a System.Xml.XPath assembly (version, as opposed to version from the Silverlight SDK) that is internally used by the XAML page loader. Now when you add the Silverlight SDK version the result is a conflict between these involved assemblies that cannot be resolved.

The problem is not related to YLAD. Here's a short test you can do: Add a new empty Windows Phone 8 class library to your Windows Phone 8 project. In that new class library, add an empty phone page. Now use the Navigate() method from within your app to navigate to the page that is located in the class library. You will receive the exact same error then, if you have added the reference to Silverlight's System.Xml.XPath before - and in the same way it works as expected when you remove that reference. As I see it, there's nothing I could do to prevent that error from happening, as it happens even before YLAD is successfully loaded, and every other component integrated in the same way will face the same problem.

As I mentioned above, the best solution would be not to use any of the XPath features. I do use LinqToXml in YLAD too, it works as advertised. In my tests, I didn't need to add the Silverlight System.Xml.XPath assembly for compilation; my samples compiled fine without it and with the HTML Agility Pack referenced. Of course I don't know if additional things need to be done once you start actively using HAP or if you have added references to these features in your code.

I hope this helps. Sorry that there won't be a simpler solution to resolve this.
Feb 2, 2013 at 7:02 PM
By the way I will still update the project (and NuGet) with a native Windows Phone 8 version in the next days, as some of the e.g. styling logic has changed a bit compared to 7.x.
Feb 2, 2013 at 8:04 PM
Hi Peter,

Thanks for the info. I know maybe it's not the right place to ask, but how do you use HTMLAgilityPack without System.Xml.XPath? I am using HTMLAgilityPack to parse an HTML file and with XPath that is very nice & easy. Is there any viable alternative? I (and maybe others too) would love to know it.