zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
449 stars 86 forks source link

Expression error using LINQ #66

Closed chenmark1 closed 4 years ago

chenmark1 commented 4 years ago

Hello!

Maybe you can help us with the below expression : state.town.buildings.Values.Any(b => b.isDamaged == true)

Unhandled exception. System.TypeInitializationException: The type initializer for 'dd_segmentation_lib.Segmentation' threw an exception. ---> System.Exception: Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 94 near ".Any(b => b.Value.isDa".

Any idea what am I doing wrong?

JonathanMagnan commented 4 years ago

Hello @chenmark1 ,

Could you give the full code including the query + expression + parameter?

At this moment, we are not sure if the issue is on your side (perhaps parameter are wrongly passed) or our side since we don't have the full information.

Best Regards,

Jon

chenmark1 commented 4 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using dd_segmentation_lib.Models;
using DDModels;
using Jil;
using Z.Expressions;

namespace dd_segmentation_lib
{
    public class SGX  // Singleton
    {
        private static SGX _instance = new SGX();
        public static SGX instance => _instance ??= new SGX();
        static SGX() { }
        private Dictionary<int, Segment> _segments;

        private SGX()
        {
            _segments = new Dictionary<int, Segment>();
            // get all active segments from redis
            var rds = Redis.instance.GetDB();
            var rdsRes = rds.HashGetAll(R.H("sgx::segments"));

            foreach (var entry in rdsRes)
            {
                var segment = JSON.Deserialize<Segment>(entry.Value);
                segment.evalFcn = Eval.Compile<Func<UserData, bool>>(segment.expression);
                _segments[segment.segmentId] = segment;
            }
        }

        public List<Segment> GetPlayerSegments(AccountState accountState)
        {
            var userData = new UserData()
            {
                state = accountState
            };

            var userSegments = new List<Segment>();
            foreach (var segmentEntry in _segments)
            {
                // Console.WriteLine($"res: {segmentEntry.Value.evalFcn(userData)}");
                if (segmentEntry.Value.evalFcn(userData))
                    userSegments.Add(segmentEntry.Value);
            }

            return userSegments;
        } 
    }
}
JonathanMagnan commented 4 years ago

Hello @chenmark1 ,

I don't think that will be enough.

We really need something we can run for this issue. That kind of issue as said is normally due to something missing or for example, state should be case sensitive State.

It's currently to hard to investigate it with the current information.

If you want to keep your code private, you can send it to us here: info@zzzprojects.com

JonathanMagnan commented 4 years ago

Hello @chenmark1,

Since our last conversation, we haven't heard from you.

As mentioned in my previous email, you can send us your code on our company's email info@zzzprojects.com.

Looking forward to hearing from you,

Jon

JonathanMagnan commented 4 years ago

Hello @chenmark1

A quick reminder that we are here to assist you.

Feel free to send us your code on our mailbox info@zzzprojects.com

Best regards,

Jon

JonathanMagnan commented 4 years ago

Hello @chenmark1

Since we haven't heard back, we will close this issue.

Feel free to contact us once you can provide more information.

Best regards,

Jon