Determine whether the BizTalk assembly is Debug or Release build at runtime.

|  Posted: June 2, 2007  |  Categories: BizTalk Server

Recently someone raised this question in the newsgroup, they wanted to branch inside the orchestration based on the build of the assembly itself. Whenever an assembly is build with “Debug” mode, some System.Diagnostics.DebuggableAttributes are added to the assembly. One such attribute is “IsJITTrackingEnabled”, which will track information during code generation (MSIL) for the debugger. So, … Continue reading Determine whether the BizTalk assembly is Debug or Release build at runtime.

Recently someone raised this question in the newsgroup, they wanted to branch inside the orchestration based on the build of the assembly itself. Whenever an assembly is build with “Debug” mode, some System.Diagnostics.DebuggableAttributes are added to the assembly. One such attribute is “IsJITTrackingEnabled”, which will track information during code generation (MSIL) for the debugger. So, we can use the simple technique of reflection to determine whether the assembly is build against “Debug” or “Release” mode by the presence or absence of IsJITTrackingEnabled attribute. The below method does exactly the same: public static bool IsDebugBuild(System.Reflection.Assembly assembly) { object[] attributes = assembly.GetCustomAttributes(typeof(DebuggableAttribute), false); if (attributes.Length == 0) return false;//No debug attibutes, so release build foreach (Attribute attr in attributes) { if (attr is DebuggableAttribute) { DebuggableAttribute d = attr as DebuggableAttribute; if (d.IsJITTrackingEnabled == true) //this flag is set only for debug builds return true; //Debug else return false; //Release } } throw new Exception(“Cannot determine the build type”); } Place the above code in an utility class (external assembly), build and GAC it. Inside your Orchestration, reference the assembly, define a variable (ex: assm) of type “System.Reflection.Assembly” and call the method IsDebugBuild as shown below inside your Expression shape assm = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.Debug.WriteLine(Utility.DetermineDebugOrRelease.IsDebugBuild(assm)); Place the above code in an utility class (external assembly), build and GAC it. Inside your Orchestration, reference the assembly, define a variable (ex: assm) of type “System.Reflection.Assembly” and call the method IsDebugBuild as shown below inside your Expression shape assm = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.Debug.WriteLine(Utility.DetermineDebugOrRelease.IsDebugBuild(assm)); NOTE: This example is just to address someone’s question. You should try NOT to use this type of code in production. Because reflection is an expensive process and it doesn’t really suits well for high throughput BizTalk applications. Nandri! Saravana

Leave a Reply

Your email address will not be published. Required fields are marked *