locked
Can't debug .NET 2.0 Assembly from unmanaged code in VS 2010 RRS feed

  • Question

  • I'm working on a project that launches the .NET runtime from within an unmanaged application and then executes code in a managed assembly.

    I've always been able to debug the .NET assembly by setting the unmanaged app as the start application for debugging and then simply setting a breakpoint in the .NET assembly.

    Since installing VS 2010 I've been unable to debug .NET 2.0 assemblies in this fashion. The unmanaged app starts and calls the .NET 2.0 code just fine but none of the breakpoints in the project code are ever hit. If I recompile the same assembly under .NET 4.0 with no other changes THEN the breakpoints hit fine. Unfortunately there are other issues in this scenario that causes problems so this isn't an option at the moment.

    Any ideas why the 2.0 assembly can't be debugged with the VS 2010 debugger?

     

    Couple of other data points here:

    --

    I'm hosting the .NET runtime myself in this app using CorBindToRuntimeEx and creating a new AppDomain to host the runtime. It appears the 2.0 runtime gets loaded up even when explicitly requesting the 4.0 runtimes (weird). Using COM Interop in the same scenario debugging doesn't work either (ie. make COM call into .NET 2.0 component doesn't break either 4.0 assembly works), so I don't think the hosting is the problem tho.

    Visual Studio 2008 won't start debugging the unmanaged application. Something about a missing debugger target. Effectively the VS 2010 install killed the VS 2008 debugging functionality for a .NET assembly loading an unmanaged app :-(

    --

    TIA for any ideas on how to track this down.

    +++ Rick ---

    Sunday, June 6, 2010 8:16 PM

Answers

  • This article discussed the issue, as well as a workaround, you may have a look.

    The problem is that the debugger is trying to determine what version of the .NET Framework your class library will load into, and the debugger has guessed incorrectly.

    The work around for this is to add a config file next to the native executable to tell the debugger what version of the .NET Framework to debug.

    So if you are trying to debug c:\proj\MyNativeProject\debug\MyNativeProject.exe, then create c:\proj\MyNativeProject\debug\MyNativeProject.exe.config with this content:

    <?xml version ="1.0"?>
    <configuration>
        <startup>
            <supportedRuntime version="v2.0.50727" />
        </startup>
    </configuration>


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    • Marked as answer by eryang Wednesday, June 16, 2010 9:24 AM
    Wednesday, June 9, 2010 4:31 AM

All replies

  •  

    I have VS2008 and VS2010 installed on same machine, in VS2010, my test result shows that if you launch 2.0 runtime against a 2.0 managed dll, the breakpoint in the dll will not hit, here is what I found with my tests:

     

    VS version

    Runtime Version

    Managed dll version

    Managed breakpoint hit?

    2010

    (10.0.30319.1 RTMRel)

    2.0

    2.0

    No

    4.0

    (not support)

    4.0

    2.0

    Yes

    4.0

    Yes

    2008

    2.0

    2.0

    Yes

     

    I’m consulting VS team about this issue, will let you know the latest status.

     

    However, have you tried to set Debugger Type to Mixed? (Right click the C++ project --> Properties --> Configuration Properties --> Debugging --> Debugger Type --> select 'Mixed').

     

    As a workaround, you may also choose VS2008 to do debugging.

     

     

    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

     

    Tuesday, June 8, 2010 11:08 AM
  • This article discussed the issue, as well as a workaround, you may have a look.

    The problem is that the debugger is trying to determine what version of the .NET Framework your class library will load into, and the debugger has guessed incorrectly.

    The work around for this is to add a config file next to the native executable to tell the debugger what version of the .NET Framework to debug.

    So if you are trying to debug c:\proj\MyNativeProject\debug\MyNativeProject.exe, then create c:\proj\MyNativeProject\debug\MyNativeProject.exe.config with this content:

    <?xml version ="1.0"?>
    <configuration>
        <startup>
            <supportedRuntime version="v2.0.50727" />
        </startup>
    </configuration>


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    • Marked as answer by eryang Wednesday, June 16, 2010 9:24 AM
    Wednesday, June 9, 2010 4:31 AM