Checking if a context property exists
I've mentioned this briefly in one of my previous posts, but really I think the subject deserves its own post -
There's a certain behaviour of BizTalk that does not fit, in my view, with a certain development guideline.
Generally, it is said, one should not use exceptions to control the flow of an application. exceptions should be there to handle, as their name suggest, exceptional situations.
What that comes down to (a very short description) is that, for example, if you're about to use a member that might contain null, it is better to encpasulate your work in an if(a!=null) block rather than using a try catch block around the access to the member to catch any NullReferenceException.
However, in BizTalk, if you try to access a context property that does not exist in the message context you will get a MissingPropertyException thrown. this means that if you need to check for the existence of a property from within an orchestration you will have to do that in a scope with an exception handler, so that if the exception was thrown you know the property does not exist, if it wasn't thrown the proeprty has a value.
While this gets the job done it is not in line with the guidance around exception handling and is not performing as well as an if (exceptions are more expensive than control flow statements)
Somewhat surprisingly in a way, there is a second option that works - you can pass your message to a helper class and use the XLANGMessage's GetPropertyValue method to access the value. this method is inconsistent with the use of context properties in an orchestration as it returns null if the property does not exist (which is good news for our purpose)
you can read more about it here