How to check if promoted property value exists before using it? (or) Using Exists Function in BizTalk (or) Missing Property Exception
Promoted properties are used in Content Based Routing and to access a frequently used value easily instead of loading the Full Message into Memory.
Generally we promote a property assuming that value for that Property exists at all the time. But what happens when a Promoted Property doesn’t exist?
Answer is MissingPropertyException.
Consider the below sample:
1. Create a new BizTalk Project with a Sample Schema having a promoted field.
2. Create a simple Orchestration to receive the message for the Schema you created in step 1 and add write the value for promoted field to EventLog.
3. Deploy the solution and Create a FILE receive location for the Orchestration Receive port. Try to drop the below file into the folder.
5. Now change the input file by removing the Promoted Field.
6. Now you see the below exception in EventLog.
xlang/s engine event log entry: Uncaught exception (see the ‘inner exception’ below) has suspended an instance of service ‘PromotedProerties.BizTalk_Orchestration1(c5ac04d8-5aa3-a384-8957-00649b78fbaf)’.
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.
Shape name: Expression_1
Exception thrown from: segment 1, progress 8
Inner exception: There is no value associated with the property ‘PromotedProerties.PropertySchema.CustomContextProperty’ in the message.
Exception type: MissingPropertyException
Using exists function to Check if Promoted Property exists or not:
To overcome the above error you can use the BizTalk Built in function called exists.
1. Modify the expression shape code given in step 2 as below.
if(PromotedProerties.PropertySchema.PromotedField exists Message_1)
System.Diagnostics.EventLog.WriteEntry(“BTIS”,”Promoted Property: “
System.Diagnostics.EventLog.WriteEntry(“BTIS”,”Promoted Property doesn’t Exist”);
2. Now when you drop the file without having the promoted field, your else part of code is executed and no exception is thrown.
This is the same even if the promoted property is of MessageContextPropertyBase Type.
1. MissingPropertyException will be thrown whenever you try to access a promoted property whose value is not assigned.
2. Use Exists function to check if the promoted property value exists or not before using the value.
3. MissingPropertyException occurs for both MessageContextPropertyBase and MessageDataPropertyBase
Hope it helps.
No comments yet.