I often forget if by default, a string variable in a BizTalk orchestration is null or an empty string. Most of the time it does not matter but sometimes it does. So this post about BizTalk Orchestration variables default values is mostly for my own use so that I don’t forget again!
To be short, the default value of a string variable in an orchestration is: String.Empty!
The problem of default values does not happen for orchestration variables of other basic types than string as they all incur a compile time error if the variable is used before a value is assigned to it. There are 2 ways to initialize an orchestration variable:
- Set a value in the “Initial Value” property of the variable’s Properties window.
- Assign a value to the variable in an Expression Shape.
The compile time error aforementioned looks like: error X2109: use of unassigned local variable ‘aVar’.
If the variable is not initialized and also not used, the compiler will not throw an error but a warning instead: warning X4005: ‘aVar’ is declared but never used.
The only exception to this rule is for boolean variables which are always initialized. Indeed when creating such a variable, the “Initial Value” property is “True” by default.
So the summary is:
Orchestration Variable Type | Default Initial Value | Compilation error if no value assigned | Compilation Warning if variable not used |
boolean | True | N/A | Yes |
string | String.Empty | N/A | Yes |
Other basic types (int32, byte, datetime, timespan…) | None | Yes | Yes |