There is no value associated with the property ‘BTS.MessageID’ in the message.

In the following orchestration (This is the HelloWorld sample application at C:\Program Files (x86)\Microsoft BizTalk Server 2013\SDK\Samples\Orchestrations\HelloWorld\)

 

 

HelloHorldOrch

Inside the message assignment shape I have added the following code.

System.Diagnostics.EventLog.WriteEntry(“HelloWorld”,InvoiceMessage(BTS.MessageID));

Now when I deploy and test the HelloWorld application, I get the following error

xlang/s engine event log entry: Uncaught exception (see the ‘inner exception’ below) has suspended an instance of service ‘Microsoft.Samples.BizTalk.HelloWorld.HelloSchedule(e0eddb10-5fb9-a44c-aa06-423456a70585)’.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: fbaf254b-ac0f-4b8d-b1ed-94a58d7f8cd9
Shape name: ConstructInvoice
ShapeId: 619c4eb0-2371-4cb6-a60c-eae729be8693
Exception thrown from: segment 1, progress 6
Inner exception: There is no value associated with the property ‘BTS.MessageID’ in the message.

REASON

There are 2 ways message gets created in the message box

1. Message is published by receive port or orchestration.
–In this case message ID will be created as soon as the message gets into the MessageBox database.

2. Message is created in orchestration using construct shape.
–In this case the message will be created first in-memory representation on orchestration and it will be created into the MessageBox database only once the persistence point comes in the orchestration.

So in the above orchestration we are trying to use the Message ID of the newly created message(InvoiceMessage) in the construct shape which is not been yet created. The Message ID is created ONLY on persistence (normally the send shape adds the persistence point) or during any activity that cause the Message to be published to the MessageBox.

SOLUTION

1. If you are using Message ID as a unique identifier may be for co-relation or something like that then its advisable to use Orchestration Instance ID,  Microsoft.XLANGs.Core.Service.RootService.InstanceId

For the scenario mentioned above I changed the code to following and it worked.

System.Diagnostics.EventLog.WriteEntry(“HelloWorld”, Microsoft.XLANGs.Core.Service.RootService.InstanceId.ToString()); 

2. You can either you the message which is already published to message box.

For the scenario mentioned above if I change the code to following it will also work because here the POMessage is already published in MessageBox by the receive port.

System.Diagnostics.EventLog.WriteEntry(“HelloWorld”, POMessage(BTS.MessageID));

 

Also refer the MSDN forum link

https://social.msdn.microsoft.com/Forums/en-US/5e6df6f2-a4cf-4e75-b2eb-ed7cb1553085/btsmessageid-is-not-working-with-new-constructed-message?forum=biztalkgeneral

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s