Skip to content

System.NotSupportedException: 'Illegal one-byte branch at position: 233. Requested branch was: 204.' #86

Open
@suriyadi15

Description

@suriyadi15

I use .NET Core 2.0 and this is the code:

class Program
{
    static void Main(string[] args)
    {
        ExpressionContext context = new ExpressionContext();

        context.Imports.AddType(typeof(AggregationOperation));

        //this not work
        string processedFormula = "IF(2.1<>2.1,IF(2.1>2.1,2.1,IF(AND(2.1>2.1,2.1<=2.1),2.1,IF(AND(2.1>2.1,2.1<=2.1),2.1,2.1))),IF(2.1>2.1,2.1,IF(AND(2.1>2.1,2.1<=2.1),2.1,IF(AND(2.1>2.1,2.1<=2.1),2.1,2.1))))";

        //this work
        //string processedFormula = "IF(2<>2,IF(2>2,2,IF(AND(2>2,2<=2),2,IF(AND(2>2,2<=2),2,2))),IF(2>2,2,IF(AND(2>2,2<=2),2,IF(AND(2>2,2<=2),2,2))))";

        processedFormula = Regex.Replace(processedFormula, @"and\(", "andF(", RegexOptions.IgnoreCase);

        var e = context.CompileDynamic(processedFormula);
        object result = e.Evaluate();

        System.Console.ReadKey();
    }
}

public static class AggregationOperation
{
    public static bool andF(params bool[] conditions)
    {
        bool result = true;

        foreach (var item in conditions)
        {
            result = result && item;
        }

        return result;
    }
}

The exception throw

System.NotSupportedException
  HResult=0x80131515
  Message=Illegal one-byte branch at position: 233. Requested branch was: 204.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.Emit.ILGenerator.BakeByteArray()
   at System.Reflection.Emit.DynamicResolver..ctor(DynamicILGenerator ilGenerator)
   at System.Reflection.Emit.DynamicILGenerator.GetCallableMethod(RuntimeModule module, DynamicMethod dm)
   at System.Reflection.Emit.DynamicMethod.GetMethodDescriptor()
   at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType)
   at Flee.InternalTypes.Expression`1.Compile(String expression, ExpressionOptions options) in D:\Code\Flee\src\Flee.NetStandard20\InternalTypes\Expression.cs:line 100
   at Flee.InternalTypes.Expression`1..ctor(String expression, ExpressionContext context, Boolean isGeneric) in D:\Code\Flee\src\Flee.NetStandard20\InternalTypes\Expression.cs:line 49
   at Flee.PublicTypes.ExpressionContext.CompileDynamic(String expression) in D:\Code\Flee\src\Flee.NetStandard20\PublicTypes\ExpressionContext.cs:line 198
   at Flee.Console.Program.Main(String[] args) in D:\Code\Flee\test\Flee.Console\Program.cs:line 27

I just changed 2 to 2.1 and it doesn't work. How to solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions