How to know DLL is in Release/Debug Mode in VS Framework 2.0

A DLL can have one of 5 states when it comes to debug/release DLLs:

1. A "non debuggable" DLL:

When opened in ilDasm.exe the manifest does not include the line:

// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) 
= ( 01 00 XX XX 00 00 00 00 )


When the DLL is dynamically loaded the call to the method:

DebuggableAttribute.GetCustomAttribute(assm, typeof(DebuggableAttribute));

returns null.

2. An optimized debug DLL:

When opened in ilDasm.exe the manifest includes the line:

// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) 
= ( 01 00 03 00 00 00 00 00 ) 


When the DLL is dynamically loaded the call to the method:

DebuggableAttribute.GetCustomAttribute(assm, typeof(DebuggableAttribute));

returns a DebuggableAttribute object with the flags 

IsJITOptimizerDisabled = false;
IsJITTrackingEnabled = true;

3. An optimized release DLL:

When opened in ilDasm.exe the manifest includes the line:

// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) 
= ( 01 00 02 00 00 00 00 00 ) 


When the DLL is dynamically loaded the call to the method:

DebuggableAttribute.GetCustomAttribute(assm, typeof(DebuggableAttribute));

returns a DebuggableAttribute object with the flags 

IsJITOptimizerDisabled = false;
IsJITTrackingEnabled = false;

4. A non-optimized debug DLL:

When opened in ilDasm.exe the manifest includes the line:

// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) 
= ( 01 00 07 01 00 00 00 00 ) 


When the DLL is dynamically loaded the call to the method:

DebuggableAttribute.GetCustomAttribute(assm, typeof(DebuggableAttribute));

returns a DebuggableAttribute object with the flags 

IsJITOptimizerDisabled = true;
IsJITTrackingEnabled = true;

5. A non-optimized release DLL:

When opened in ilDasm.exe the manifest includes the line:

// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) 
= ( 01 00 06 01 00 00 00 00 ) 


When the DLL is dynamically loaded the call to the method:

DebuggableAttribute.GetCustomAttribute(assm, typeof(DebuggableAttribute));

returns a DebuggableAttribute object with the flags 

IsJITOptimizerDisabled = true;
IsJITTrackingEnabled = 
false;

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now