0

I have a main Program A which calls a dllB method.

dllB is build in release mode. Depending on which mode the Program A is build(Release/Debug) the result should be returned appropriately but it always returns "releaseMode".

So is there a way where i can reference dllB in release mode and depending on the main program preference(Release/Debug) get the result.

Program A---
main ()
{
  var dllbObj = new dllB();
  var response = dllObj.CallMethod();
 //Release mode should return "releaseMode" 
 //and debug mode should return "debugMode"
}

dll B---
public string CallMethod()
{
 string res;
#if DEBUG
            res = "debugMode";
#endif
            res = "releaseMode";

            return res;
}
Mangesh
  • 3,987
  • 2
  • 31
  • 52

2 Answers2

1

There's no way to achieve this with pragmas, because they are baked into the assembly at compile-time. If the second assembly is compiled in Release mode, it doesn't contain any code that might have been placed in a DEBUG section.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks Darin but then what is the best way to use 2 dlls one for debug and one for release.Can you suggest. – Mangesh Jul 06 '12 at 17:10
  • If you have the source code of the second assembly you could recompile it according to the mode of the main assembly. If you don't, then you simply don't have the source code of this secondary assembly for the DEBUG mode, so you can't do anything. – Darin Dimitrov Jul 06 '12 at 17:12
1

There is no way to accomplish this as A.exe and B.dll are compiled independently of each other. When B is compiled in Release the "debugMode" string simply won't exist in B.dll in any shape or form. It is completely ignored by the compiler.

The only way to have A.exe get the debug or release string from B.dll is to have them both match on their compilation. Either compile them both in Debug or both in Release but don't mix it.

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454