StefH / XPath2.Net

Lightweight XPath2 for .NET
Microsoft Public License
36 stars 14 forks source link

XPath2Expression.Compile throws exception in Mono #33

Closed andrew-moore-octo closed 4 years ago

andrew-moore-octo commented 4 years ago

XPath2Expression.Compile throws an exception in Mono. It appears that the XmlCharType.bin resource doesn't exist in System.Xml under Mono, which causes this line to throw a NullReferenceException.

From my brief experiments, it looks like using the netstandard version of InitInstance works okay on Mono, although I'm not sure if there would be any side effects to using that instead.

Minimal code example

using Wmhelp.XPath2;

namespace MonoTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            XPath2Expression.Compile("//node");
        }
    }
}

Steps to repro

  1. Install Mono if it's not already installed
  2. Compile the code above
  3. Run the code above with mono MonoTest.exe
  4. Observe exception

Affected versions

Mono versions: 4.4.2 and 6.10.0 (latest available through choco at time of writing) Xpath2 versions: 1.0.11

StefH commented 4 years ago

@andrew-moore-octo

Thanks for reporting.

A possible solution would be to use the netstandard code if running in mono. (Detecting mono can be done like : https://stackoverflow.com/questions/721161/how-to-detect-which-net-runtime-is-being-used-ms-vs-mono)

I'll take a look.

StefH commented 4 years ago

@andrew-moore-octo I did update the code, can you try a preview version from MyGet : XPath2.1.0.12.nupkg ?

(MyGet : https://www.myget.org/feed/xpath2/package/nuget/XPath2/1.0.12) Details on how to use MyGet: https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

andrew-moore-octo commented 4 years ago

@StefH Thanks for fixing that so quickly! I've tested version 1.0.12 against the following runtimes:

Everything is working perfectly 👍

StefH commented 4 years ago

New official version will be released soon.

https://github.com/StefH/XPath2.Net/pull/34