Monday, January 22, 2007

How to Debug a BizTalk Rules Policy in Code

Rule engine - Another way to debug the rule engine

I was experiencing an unreported error when I was trying to dynamically call a BizTalk 2006 rules policy in C# code. The policy ran and gave me no exception information and was annoying me to no end!

It turns out the issue had to do with facts and namespaces. I didn't discover this, however, until I learned from the link above how to put a debug trace into the policy so it would tell me what was going on.

Here's a snippet:

TypedXmlDocument typedResult = new TypedXmlDocument("ValidationResult", validationResult);
TypedXmlDocument typedTransaction = new TypedXmlDocument("Transaction", transaction);

System.Collections.ArrayList FactList = new System.Collections.ArrayList();
FactList.Add(typedResult);
FactList.Add(typedTransaction);

DebugTrackingInterceptor debug = new DebugTrackingInterceptor(@"D:\trace.txt");
Policy rulePolicy = new Policy("ValidateTransaction");
rulePolicy.Execute(FactList.ToArray());
rulePolicy.Dispose();

No comments: