Thursday, September 3, 2009

The XLANG/s runtime failed in terminating the instance

I have a scope in my orchestration the construct 2 different XLANG messages and add entry in the database.



In order to handle failure gracefully, I add an Exception Handler to perform error handling and then terminate the orchestration. However, when I run the orchestration, I get the following error message.

Event Type: Error
Event Source: XLANG/s
Event Category: None
Event ID: 10001
Date: 6/9/2009
Time: 9:34:26 PM
User: N/A
Computer: TOR-12653
Description:
The XLANG/s runtime failed in terminating the instance 99f16670-471d-4cb2-a299-3c5f84547efd of service type "ArielBPM.BizTalk.RequestManagement.LOC.Orchestrations.Orch_CobraCoverageTermination". Exceptions.Messages.Preparation

Exception type: BTXServiceTerminateFailedException
Source: System.Xml
Additional error information:


The string '' is not a valid Boolean value.

Exception type: FormatException
Source: System.Xml
Target Site: Boolean ToBoolean(System.String)
The following is a stack trace that identifies the location where the exception occured


at System.Xml.XmlConvert.ToBoolean(String s)
at Microsoft.XLANGs.RuntimeTypes.XmlHelpers.ParseString(String s, Type targetType, Boolean throwIfNotParsed)
at Microsoft.XLANGs.RuntimeTypes.XmlHelpers.ChangeType(Object val, Type targetType)
at Microsoft.XLANGs.Core.XMessage.GetContentProperties()
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.PrepareMessage(XLANGMessage msg, IList promoteProps, IList toPromote)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.PersistMessageState(XLANGMessage msg)
at Microsoft.XLANGs.Core.XMessage.PrePersist(Boolean dehydrate, IStateManager state)
at Microsoft.XLANGs.Core.ReferencedMessages.PrePersist(Boolean dehydrate, Context state)
at Microsoft.XLANGs.Core.Context.PrePersist(Boolean dehydrate, Context state)
at Microsoft.XLANGs.Core.Context.PrePersist(Boolean dehydrate, XlangStore store)
at Microsoft.XLANGs.Core.ExecutingSubStates.PrePersist(Boolean dehydrate, Context ctx)
at Microsoft.XLANGs.Core.Context.PrePersist(Boolean dehydrate, Context state)
at Microsoft.XLANGs.Core.ServiceContext.PrePersist(Boolean dehydrate, Context state)
at Microsoft.XLANGs.Core.Service.PrePersist(Boolean dehydrate, Context ctx)
at Microsoft.XLANGs.Core.Service.Persist(Boolean dehydrate, Context ctx, Boolean idleRequired, Boolean finalPersist, Boolean bypassCommit, Boolean terminate)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXService.TerminateSchedule(Envelope env)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.



As you can see from the image above, there's no mechenism to retry or loop after Exception is caught. However, this doesn't seem to reflect the reality. When I get this error message, the orchestration instance is not terminated, nor it's suspended. Instead, after the above XLANG error is thrown, the entire orchestration is restarted all the way from the beginning and it keeps looping like this indefintely.

I try Googling it, however, the only place that I can find that has similar exception is here: http://www.eggheadcafe.com/forumarchives/biztalkorchestration/Oct2005/post24389371.asp. He/she was able to fix the problem by changing the scope's transaction type from "Long Running" to "None". However, the transaction type of my failing scope is "None" to start with. Hence it doesn't seem like the solution for my problem.

After studying the error message more closely with my colleague , we are suspecting the orchestration fails when it tries persist to the database. In order to confirm that, I purposely put a "Delay" shape before the "Terminate" shape, which will force the orchestration to be de-hydrated.
It turns out that the test result confirms our theory. I get the same error message when the "Delay" shape is being executed. It seems like we are one step closer to finding out the root cause of the problem.

So, what cause the orchestration to fail when it tries to persist the state to the database? This remains to be the mystery, but not for long. After looking through my orchestration and the error message a couple more times, I find a clue that directs me to the offending shape that cause the problem.

Firstly, the error message says "The string '' is not a valid Boolean value", which indicates it's trying to convert a empty string to a Boolean value. This reminds me that I have a created an empty message before the failure point (in the "Init" Expression shape)


construct MSG_ArielBPMLOC_Common{
MSG_ArielBPMLOC_Common = ArielBPM.Biztalk.Helper.XLANG.Construction.ConstructEmptyMessage (typeof(ArielBPM.BizTalk.RequestManagement.LOC.InternalSchemas.ArielBPMLOC));
}





The reason that I creating an empty message before the "Decide" shape is as follows. My orchestration listens for 2 different message types as possible inputs. Depends on the message type received, a common message type is being constructed in both branches of the "Decide" shape. However, because of the way the "Decide" shape is implemented, although the same message is being constructed in both branches, it still complains about "use of unconstructed message" when I try to compiles the solution. Because of this, I have to explicitly construct a dummy empty common message before the "Decide" shape. The created empty message is only an instance of the schema without any data (similar to xml below):

<RootNode>
<BooleanTypeElement />
<StringTypeElement />
<IntegerTypeElement />
</rootnode>


An error (Microsoft.XLANGs.RuntimeTypes.XPathUpdateException - see below) occur before the common mesage the constructed in one of the "Decide" shape branches. The "Exception Handler" catches the exception and it tries to terminate the orchestration using the "Terminate" shape.


Type: Microsoft.XLANGs.RuntimeTypes.XPathUpdateException

Message: A failure occurred while evaluating the distinguished field RequestHeader.RequestID against the message part data. The message part data does not contain at least one of the nodes specified by the XPath expression (listed below) that corresponds to the distinguished field. The cause for this error may be that the message part data has not been initialized or that the message part data does not conform to the message part schema. Ensure that the message part data is initialized correctly. XPath expression: /*[local-name()='LossOfCoverageRequest' and namespace-uri()='http://ArielBPM.Biztalk.RequestManagement.LOC.InternalSchemas']/*[local-name()='RequestHeader' and namespace-uri()='http://ArielBPM.Biztalk.RequestManagement.LOC.InternalSchemas']/*[local-name()='RequestID' and namespace-uri()='http://ArielBPM.Biztalk.RequestManagement.LOC.InternalSchemas']

StackTrace:
at Microsoft.XLANGs.Core.XSDPart.SetDistinguishedField(String dottedPath, Object val)
at ArielBPM.BizTalk.RequestManagement.LOC.Orchestrations.Orch_CobraCoverageTermination.segment6(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

Source: Microsoft.XLANGs.Engine


I believe when the "Terminate" shape is being executed, it tries to evaluate (or validate) the empty common message before it persist its state to the database. However, since the common message is still empty and validation will fail when it validates an empty element which is supposed to be of type boolean. In order to test my theory, I make the following changes in the "Init" Express shape to construct the common message and populate it with some dummy data.


construct MSG_ArielBPMLOC_Common{
MSG_ArielBPMLOC_Common = ArielBPM.Biztalk.Helper.XLANG.Construction.ConstructMessageWithData (typeof(ArielBPM.BizTalk.RequestManagement.LOC.InternalSchemas.ArielBPMLOC));
}



As soon as I make this changes to the orchestration, although I am still getting the Microsoft.XLANGs.RuntimeTypes.XPathUpdateException, the "Exception Handler" is able to catch the exception and terminate the orchestration successfully.