Git Product home page Git Product logo

Comments (5)

OPunktSchmidt avatar OPunktSchmidt commented on May 27, 2024

I have created a very minimalistic repository to reproduce the error on ios. It is an Xamarin.Forms project. When you start the iOs Project a exception is thrown, on Android not.

https://github.com/OPunktSchmidt/NRecoLambdaParser.Issue21.XamarinForms

This is the relevant test code. It is placed in App.xaml.cs and is exceuted immediately on when starting the project.

    protected override void OnStart()
    {
        // Handle when your app starts

        try
        {
            NReco.Linq.LambdaParser parser = new NReco.Linq.LambdaParser(new NReco.Linq.ValueComparer() { NullComparison = NReco.Linq.ValueComparer.NullComparisonMode.Sql });

            string evalString = "(val1.Contains(val2) || val3.Contains(val4) || val5.Contains(val6) || val7.Contains(val8) || val9.Contains(val10) || val11.Contains(val12) || val13.Contains(val14) || val15.Contains(val16) || val17.Contains(val18) || val19.Contains(val20))";

            System.Collections.Generic.Dictionary<string, object> values = new System.Collections.Generic.Dictionary<string, object>();
            values.Add("val20", "10;");
            values.Add("val17", "2;4;5;7;8;");
            values.Add("val12", "6");
            values.Add("val7", "2;4;5;7;8;");
            values.Add("val2", "1");
            values.Add("val19", "2;4;5;7;8;");
            values.Add("val13", "2;4;5;7;8;");
            values.Add("val8", "4");
            values.Add("val3", "2;4;5;7;8;");
            values.Add("val1", "2;4;5;7;8;");
            values.Add("val5", "2;4;5;7;8;");
            values.Add("val16", "8");
            values.Add("val18", "9");
            values.Add("val14", "7");
            values.Add("val4", "2");
            values.Add("val11", "2;4;5;7;8;");
            values.Add("val9", "2;4;5;7;8;");
            values.Add("val10", "5");
            values.Add("val15", "2;4;5;7;8;");
            values.Add("val6", "3");

            object evalResult = parser.Eval(evalString, values);

            System.Diagnostics.Debugger.Break();
        }
        catch (System.Exception ex)
        {
            System.Diagnostics.Debugger.Break();
        }
    }

from lambdaparser.

VitaliyMF avatar VitaliyMF commented on May 27, 2024

Oliver, do you have any idea how to fix this incompatibility on iOS? I don't have enough expertise on .net+mobile platform. It seems LambdaParser tries to create a delegate that doesn't available on ios (Func<>?).

from lambdaparser.

OPunktSchmidt avatar OPunktSchmidt commented on May 27, 2024

I haven't had a closer look. But in this depth I don't have much expertise in mobile development either.

I'll take a closer look at it. I'll be on vacation next week but I'll definitely get closer to it when I'm back in the office.

I'll keep you informed.

from lambdaparser.

OPunktSchmidt avatar OPunktSchmidt commented on May 27, 2024

I did some research.

"Since the iOS kernel prevents an application from generating code dynamically, Xamarin.iOS does not support any form of dynamic code generation." (https://docs.microsoft.com/bg-bg/xamarin/ios/internals/limitations)

Simple expressions like "val1 == val2" or "val1 > val2" seems to work on iOs, but more complex expressions like mine above not (there is a methode-call to "Contains in the expression).

Maybe the method-call to "Contains" requires something from namespace System.Reflection.Emit? System.Reflection.Emit is not available due to limitations under ios. I haven't worked much with dynamic code generation and System.Linq.Expressions so far so I can't say much about it.

Here are a few more interesting links:

https://stackoverflow.com/questions/19666257/how-to-compile-methodcallexpression-without-dynamicinvoke
https://stackoverflow.com/questions/24977939/what-does-expression-compile-do-on-monotouch
https://stackoverflow.com/questions/29245589/why-does-lambdaexpression-compile-work-on-ios-xamarin

I'll keep investigating...

from lambdaparser.

VitaliyMF avatar VitaliyMF commented on May 27, 2024

According to this documentation page, dynamic code generation is not supported on iOS; from the other side, NReco.LambdaParser uses only System.Expressions which should fallback to 'interpretation' mode on iOS. You reported that "val1 == val2" or "val1 > val2" work fine, so I may assume that an error may be caused by a bug related to the MethodCallExpression 'interpretation'.

First of all, it is good idea to test expression like "val3.Contains(val4)" with latest Xamarin platform, maybe this issue is already solved. If this doesn't help, you can modify LambdaParser class to use Expression.Compile(true) to force interpretation mode - who knows maybe this is needed for iOS.

Finally, execution of expressions on iOS 100% might be possible with own LambdaParser 'interpretation' (however this will require some development + I assume evaluation performance may be not so good).

from lambdaparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.