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

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

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

Author: Saravana Kumar

Saravana Kumar is the Founder and CTO of BizTalk360, an enterprise software that acts as an all-in-one solution for better administration, operation, support and monitoring of Microsoft BizTalk Server environments.

One Platform Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

One Platform - Operations, Monitoring and Analytics Software
BizTalk360

microsoft biztalk

Learn more

Over 500 customers across 30+ countries depend on BizTalk360

One Platform - Operations, Monitoring and Analytics Software
ServiceBus360

Azure service bus

Learn more

Start managing your Azure Service Bus namespaces in minutes

Back to Top