jeudi 16 juin 2016

The given ruleset does not contain any rules with type System.Object, mscorlib,

First, I am using www.codeeffects.com framework to make a business rule evaluator, but in my case I need the types to be 100% dynamic.

I have the following code in my Proof of Concept method.

public ActionResult Save(RuleModel ruleEditor)
        {
            DummyEntitiesGen gen = new DummyEntitiesGen();
            Type t = gen.CreateType();
            List<dynamic> lista= gen.CreateTypeList();
            // At this point the rule model doesn't know which type to use as its source object
            // We need to "bind" the source type to the rule model
            ruleEditor.BindSource(t);

            // Add the rule model to the ViewBag object
            ViewBag.Rule = ruleEditor;

            // Make sure that the Rule Area is not empty and the current rule is valid
            if (ruleEditor.IsEmpty() || !ruleEditor.IsValid(StorageService.LoadRuleXml))
            {
                ViewBag.Message = "The rule is empty or invalid";
                return View("Index");
            }

            try
            {
                // Save the rule
                StorageService.SaveRule(
                    ruleEditor.Id,
                    ruleEditor.GetRuleXml(),
                    ruleEditor.IsLoadedRuleOfEvalType == null ?
                        true : (bool)ruleEditor.IsLoadedRuleOfEvalType);

                // Get all rules for Tool Bar and context menus and save it in the bag
                this.LoadMenuRules();

                DynamicEvaluator evaluator = new DynamicEvaluator(ruleEditor.GetRuleXml());               
                //bool success = evaluator.Evaluate(lista, ruleEditor.Id);

                IEnumerable<dynamic> result = lista.Filter<dynamic>(ruleEditor.GetRuleXml());
                //var result = lista.AsQueryable<t>().Filter(ruleEditor.GetRuleXml());


               ViewBag.Message = "The rule was saved successfully";
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
            }

            return View("Index");
        }

the object lista is fine and returns a list of dynamic types created that I can see at debug time.

However the line that is supposed to filter is giving me this exception:

The given ruleset does not contain any rules with type System.Object, mscorlib





Aucun commentaire:

Enregistrer un commentaire