Support #5534


SaxonCS crashes on Android

Added by Martin Honnen almost 2 years ago. Updated 9 months ago.

Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


.NET 6 MAUI GA is there and unfortunately any attempt on Android to do/use more than new Processor() crashes, the output suggests the crash occurs while or after the class constructor/initializer for Saxon.Hej.type.BuiltInAtomicType:

[Mono] Running class .cctor for Saxon.Hej.lib.ConversionRules from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for Saxon.Hej.value.StringToDouble11 from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for Saxon.Hej.type.StringToDouble from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for System.Collections.Concurrent.ConcurrentDictionary`2<int, Saxon.Hej.expr.sort.LFUCacheEntryWithCounter`1<Saxon.Hej.type.Converter>> from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/System.Collections.Concurrent.dll'
[Mono] Running class .cctor for Saxon.Hej.value.GDateValue from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for Saxon.Hej.value.CalendarValue from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for Saxon.Hej.value.Whitespace from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[Mono] Running class .cctor for System.Collections.Generic.List`1<Saxon.Hej.regex.Operation> from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/System.Private.CoreLib.dll'
[Mono] Running class .cctor for System.Collections.Generic.List`1<Saxon.Hej.regex.RegexPrecondition> from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/System.Private.CoreLib.dll'
[Mono] Running class .cctor for Saxon.Hej.type.BuiltInAtomicType from '/data/data/com.companyname.saxoncs113mauigatest1/files/.__override__/SaxonCS.dll'
[libc] Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10 in tid 5896 (s113mauigatest1), pid 5896 (s113mauigatest1)

I can't tell whether it is the cause of the crash, not sure whether anyone at Saxonica can but as you wanted to be informed on cross platform issues with SaxonCS I open this to have an issue to track.

I don't know of any way to use SaxonCS with .NET 6 on Android other than using it with MAUI.


Actions #1

Updated by Martin Honnen almost 2 years ago

I attach a minimal MAUI project that runs fine for me under Windows (after adding a saxon-license.lic file to the project and marking it in Visual Studio with build action "MAUI asset") but crashes on Android when any of the buttons is clicked (which try to use XPath or XSLT or only to create an XdmAtomicValue).

Actions #3

Updated by Martin Honnen over 1 year ago

The MS guys seem to get to the bottom of the crash: Now idea whether that means they can fix it.

Actions #4

Updated by Martin Honnen over 1 year ago

Looks like the fix (or at least a fix) might make it into .NET 6 and .NET 7. So with the next .NET update I probably have another shot at trying to run SaxonCS under Android.

Actions #5

Updated by Martin Honnen over 1 year ago

I am now trying to run on a Mac M1 arm64 with Mono in a console app, there I at least get some stack trace of .NET code before the crash:

	Managed Stacktrace:
	  at <unknown> <0xffffffff>
	  at <unknown> <0xffffffff>
	  at System.Object:__icall_wrapper_mono_generic_class_init <0x00007>
	  at System.Impl.Helpers.DotNetPullProvider:getAttributes <0x0018f>
	  at Saxon.Hej.pull.PullPushTee:copyEvent <0x002df>
	  at Saxon.Hej.pull.PullPushTee:next <0x00043>
	  at Saxon.Hej.pull.PullConsumer:consume <0x00067>
	  at Saxon.Hej.pull.PullPushCopier:copy <0x000db>
	  at Saxon.Hej.pull.PullSource:deliver <0x00123>
	  at Saxon.Hej.event.Sender:send <0x0050b>
	  at Saxon.Hej.Configuration:buildDocumentTree <0x00303>
	  at Saxon.Hej.regex.charclass.Categories:build <0x00217>
	  at Saxon.Hej.regex.charclass.Categories:getCategory <0x0008b>
	  at Saxon.Hej.regex.charclass.Categories:.cctor <0x00507>
	  at System.Object:runtime_invoke_void <0x0007f>
	  at <unknown> <0xffffffff>
	  at <unknown> <0xffffffff>
	  at Saxon.Hej.regex.RECompiler:parseCharacterClass <0x0035f>
	  at Saxon.Hej.regex.RECompiler:parseTerminal <0x00337>
	  at Saxon.Hej.regex.RECompiler:piece <0x0005b>
	  at Saxon.Hej.regex.RECompiler:parseBranch <0x00083>
	  at Saxon.Hej.regex.RECompiler:parseExpr <0x001db>
	  at Saxon.Hej.regex.RECompiler:compile <0x0036f>
	  at Saxon.Hej.regex.ARegularExpression:.ctor <0x001b3>
	  at Saxon.Hej.regex.ARegularExpression:compile <0x0005f>
	  at Saxon.Hej.value.Whitespace:.cctor <0x0003f>
	  at System.Object:runtime_invoke_void <0x0007f>
	  at <unknown> <0xffffffff>
	  at <unknown> <0xffffffff>
	  at Saxon.Hej.value.GDateValue:setLexicalValue <0x00057>
	  at Saxon.Hej.value.DateValue:.ctor <0x0004f>
	  at Saxon.Hej.value.DateValue:.ctor <0x00043>
	  at License:daysLeft <0x0013f>
	  at Saxon.Eej.config.Verifier:configure <0x0043b>
	  at Saxon.Eej.config.Verifier:readLicenseFile <0x0006f>
	  at Saxon.Eej.config.Verifier:loadLicense <0x00103>
	  at Saxon.Impl.Overrides.Verifier:loadLicense <0x00053>
	  at Saxon.Eej.config.Verifier:loadPrimaryLicense <0x0005f>
	  at Saxon.Eej.config.ProfessionalConfiguration:loadLicense <0x0003b>
	  at Saxon.Eej.config.EnterpriseConfiguration:checkLicensedFeature <0x001ef>
	  at Saxon.Api.Processor:checkLicense <0x00067>
	  at Saxon.Api.Processor:NewXPathCompiler <0x0002f>
	  at Program:<Main>$ <0x00143>

I am curious, is that stack trace with regular expression classes at Saxon.Hej.regex.charclass.Categories:build <0x00217> at Saxon.Hej.regex.charclass.Categories:getCategory <0x0008b> at Saxon.Hej.regex.charclass.Categories:.cctor part of Saxon's attempt to check its license or is that just infrastructure set up for the XPath evaluation the program tries?

C# code is e.g.

using Saxon.Api;

Console.WriteLine($"{Environment.Version} {Environment.OSVersion}");

var processor = new Processor(true);

Console.WriteLine($"{processor.ProductTitle} {processor.ProductVersion}");

Console.WriteLine($"current-dateTime(): {processor.NewXPathCompiler().Evaluate("current-dateTime()", null)}");

It seems to run with Mono you do e.g. dotnet run -p:UseMonoRuntime=true --self-contained -r RID e.g. on this M1 arm64 Mac OS 12 dotnet run -p:UseMonoRuntime=true --self-contained -r osx.12-arm64.

I so far don't understand whether that is comparable to run under Android but it is so much easier to use a command line app than to have all that effort to write a MAUI app. And the above approach seems to be what the MS guy fixing the bug within the .NET runtime does for his reduced test case anyway, thus if a new, fixed .NET 7 (or perhaps, if the fix also makes it into a .NET 6 update, .NET 6) is released, it will be easier to check this way whether the fix allows running SaxonCS.

Actions #6

Updated by Michael Kay over 1 year ago

It's reading the license file (successfully, it seems), and testing whether it has expired. To do this it uses the DateValue class to process the expiry date, and this in turn invokes the Whitespace class.

The Whitespace class in Saxon 11 has a couple of static variables that are pre-compiled regular expressions [this is no longer the case on the 12.x branch], so this invokes initialisation of the regex engine, which involves reading and parsing the embedded categories.xml file which holds Unicode character data. This is the first use of an embedded resource file and we're rather used to it showing up any build problems.

The stack trace suggests to me that the categories.xml file has been successfully located, and that the error occurs trying to parse it with the XML Reader. In fact, it looks as if parsing has started successfully, because we must have successfully retrieved a start tag before we call getAttributes(). The getAttributes() method makes various calls on the XmlReader, and one of these calls is crashing.

Actions #7

Updated by Martin Honnen over 1 year ago

.NET 7 RC 2 (release candidate 2) came out yesterday but unfortunately the fix the Microsoft guy(s) created due to my bug report didn't end up in this release candidate, so no progress here, other than their statement that the fix is slated for the final .NET 7 released in November. Unfortunately, as far as I have asked and got answers, they have only tested that their test case(s) do work with the fix, but didn't check whether SaxonCS also runs, so whether that fixed runtime problem was the only problem preventing the use of SaxonCS under Android or the Mono runtime remains to be seen.

Actions #8

Updated by Michael Kay over 1 year ago

Thanks for your efforts on this.

Actions #9

Updated by Martin Honnen over 1 year ago

With the .NET 7 GA release of today and also with today's Windows/Microsoft patch day .NET 6 update my pet projects trying to use SaxonCS with MAUI and .NET don't crash any longer under Android emulators on Windows. So Microsoft's @lambdageek somehow managed to identify and isolate the core problem of SaxonCS's use of the Mono runtime in and his fix, now that it has made its way into the official .NET releases, opens up some SaxonCS and .NET cross-platform feeling by being able to write code in C# that runs under Windows and Android. If there weren't the license algorithm problem with MacCatalyst it would probably also work on iOS and MacOS, we'll might be able to see once there is a SaxonCS HE release where the license algorithm problems doesn't occur.

I will do some more testing in the next days to see whether some more serious XSLT/XQuery than the trivial tests I have so far work under Android but will close this issue unless I find some other crash.

Actions #10

Updated by Martin Honnen over 1 year ago

As unit testing is so far not supported for MAUI/Android and .NET 7 or 6 I can't run any test suite through SaxonCS on Android, but the originally reported crash is definitely gone with .NET 7 GA and the .NET 6 November update so this can be closed as fixed/resolved.

Actions #11

Updated by Michael Kay 9 months ago

  • Status changed from New to Closed

Please register to edit this issue

Also available in: Atom PDF