How to check if promoted property value exists before using it?
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.
InstanceId: 6d22d40a-d5f8-4e78-9226-f4d87883b5b9
Shape name: Expression_1
ShapeId: bbb266d5-bd6f-497e-9357-83602ea1f3d9
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: “
+ Message_1(PromotedProerties.PropertySchema.PromotedField));
}
else
{
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.
Observations:
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.
– Shiv
How to check if promoted property value exists before using it?
![#1 all-in-one platform for Microsoft BizTalk Server management and monitoring](https://www.biztalk-server-tutorial.com/wp-content/uploads/2022/11/biztalk-cta-learnmore.jpg)