locked
Debugging C++ DLL in ASP.NET RRS feed

  • Question

  • User-1718610407 posted

    Dear all,

    Hi, I am facing the problem of debugging or step into a C++ DLL source code in a ASP.NET solution.

    I've already added the C++ DLL source code as a project in that ASP.net solution, but it can not be debugging or stepped into.

    Also, I can only find a "ASP.NET" debugger option in Start Options of the .NET solution property pages, there is no choice as "Native Code".

    I am working on this for several days and tried to seek help from different people. But without any results.

    Can anyone please help me on this ?

     

    Thanks Very Much! 

    Li Zhang

    Wednesday, April 25, 2007 3:50 AM

Answers

  • User-1718610407 posted

    BTW,  Someone instructed about how a C++ DLL can be debugged in ASP.net

    But it just does not work for me, though I am using VS2005, I don't have a "Native Code" option in the project property page.

    Following was the POST:

     

    Hello,

    I have written an ASP .Net application that calls methods in a C++ DLL developed in Visual Studio 6.0.  The DLL itself is located within the bin directory of the .Net app during normal execution.

    I would like to debug a method within the DLL.  Typically, I would do this by specifying the exectuable for the debug session from within VS6 and initiating the program from there.  However, in this situation that doesn't work.

    Is there a way to do this?  And, is there a more appropriate forum category in which this question might be asked?

    Any help appreciated,

    Fred

     

    You don't have to use VS6. You can use VS 2003 or VS 2005 which support mixed debugging and stepping through interop. Right-click on the Web site node in the solution explorer, choose Properties and then Start Options. Check 'Native code' in addition to the ASP.NET debugger. This way you should be able to step into the C++ code directly from ASP.NET code.

    Question: why you are not using VS 2003/2005 C++? You can add C++ project to the same solution as the Web site and consume C++ project outputs in the Web site bin folder.


    Thanks
     
    <script src="http://www.asp.net/Avatar/default.ashx?u=fyale&i=1197760" type=text/javascript></script>

  •  

     

  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 27, 2007 3:18 AM

All replies

  • User-319574463 posted

    Why not log a number of sets of values supplied to DLL by you ASP.NET.

    Next write a C++ command line program to call the DLL, query for the required values so you enter them and debug from there.

    Wednesday, April 25, 2007 12:56 PM
  • User-1718610407 posted

    Thanks very much, TATWORTH,

    I've tried the first method. It does not clear imply of what the data flow are and where they go. I really need to step into the code and trace.

    By the second method that you have mentioned, I am not very clear about how to do it, can it step into the code by doiing this?

    Could you please specified it more clearly ? I am new to ASP.net, and I am a green hand coder.

    Thanks again !

    I really wonder if there is a way that can make the debugger step into the DLL code, does anyone knows?

    Wednesday, April 25, 2007 1:08 PM
  • User-1718610407 posted
    [:'(][:'(][:'(][:'(]
    Wednesday, April 25, 2007 1:23 PM
  • User-319574463 posted

    >I've tried the first method. It does not clear imply of what the data flow are and where they go. I really need to step into the code and trace.
    >By the second method that you have mentioned, I am not very clear about how to do it, can it step into the code by doing this?

    Instead of trying to debug from ASP.NET into the C++, approach the problem differently. 

    >Could you please specified it more clearly ? I am new to ASP.net, and I am a green hand coder.

    You need to trap the values that are being passed to the DLL. You can do this in a number of ways:

    • By setting a breakpoint on the call line and get the value from the debug windows.
    • By writing the values to a label. - This is better as you are not interrupting the process flow.
    • By writing the values to a custom event log.- this has the advantage of allowing you to trap a large number values. Please see my posting on thread http://forums.asp.net/thread/1631102.aspx for some sample code on how to create a custom event log and a library that facilitates writing to it.
    • By writing to trace - not such a good idea,
    Of these ideas the one I prefer is to write to a custom event of as it is the least intrusive. I have ASP.NET errors that did not yield to conventional debugging by label or break point, yet were simple to solve using the custom event log technique.

     Now once you got your test values, write a simple test harness in C++ to call your C++ DLL. Since you will now be calling from C++ to C++, debugging will be simple.

    Wednesday, April 25, 2007 3:05 PM
  • User-1718610407 posted

     

    Thanks very much, TATWORTH.

    I will try to follow the instructions you have provide. :)

    Wednesday, April 25, 2007 11:05 PM
  • User-1718610407 posted

    [:(]  I tried to log and revise my C++ DLL.

    Also, I tried to get the same input that the ASP.net will give to my C++ DLL;  It works in a C++ project. 

    However, whenever I call my C++ DLL in ASP.net, it throw out an exception, I do not know where the exception lies.

    Though this log method works, but it really needs a lot of effort as , because the C++ DLL is a big project.

     So if only I can debug it and trace into it...

    Headache. [+o(]

    Why does it works well in C++, but throw exceptions in ASP.net, even using the same input ?

     

    Thursday, April 26, 2007 5:18 AM
  • User-319574463 posted

    Does the call from ASP.NET to C++ fail every time or only on some values?

    Are you logging at the ASP.NET end? Are logging the exception and the data values that were were fed?

    What data types are being passed?

    Please post the lines of the call in ASP.NET, indcating the data types of all the variables. Also please post the C++ function header.

    Thursday, April 26, 2007 7:23 AM
  • User743145481 posted

    Why not go back to the C++ code, copy the project and work with it as a Console (or whatever you want) application?  It will be much easier to debug that way because otherwise you are just going to be doing guess and check with logged exceptions.

    You can also post the failing C++ code and I or someone else can probably help.

    Thursday, April 26, 2007 11:17 PM
  • User-1718610407 posted

    The C++ DLL provides several methods, and the call failed at only one method:

    In ASP.net:

    public class SomeAlgorithmWrapper{

            ......
       

        [DllImport("TemplateDLL.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
        public static extern Int32 GetTitle(String strPage, int iLenIn, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbResult, int iLenOut);

            ......

        StringBuilder sbTitleResult = new StringBuilder(5000);
        GetTitle(strParserResult, strParserResult.Length, sbTitleResult, 5000);        // exceptions happen at this line, but I can not step into this function

        // it works well in C++ project, using the same input in ASP.net

        // The variable types work here. Because the log kept some correct results, but failed to log and stopped in the middle of where the exception lies.

        // Also, in this function, I called a Part-Of-Speech tagging C++ DLL written by others, the exception may also caused by this DLL :(

          ......

    }

     

    Its C++ function header:  

      public static extern Int32 GetTitle(wchar_t *wszPage, int iLenIn, wchar_t *wszResult, int iLenOut);

     

    // Picky is right, I am doing guess and check :(

    Friday, April 27, 2007 3:08 AM
  • User-1718610407 posted

    BTW,  Someone instructed about how a C++ DLL can be debugged in ASP.net

    But it just does not work for me, though I am using VS2005, I don't have a "Native Code" option in the project property page.

    Following was the POST:

     

    Hello,

    I have written an ASP .Net application that calls methods in a C++ DLL developed in Visual Studio 6.0.  The DLL itself is located within the bin directory of the .Net app during normal execution.

    I would like to debug a method within the DLL.  Typically, I would do this by specifying the exectuable for the debug session from within VS6 and initiating the program from there.  However, in this situation that doesn't work.

    Is there a way to do this?  And, is there a more appropriate forum category in which this question might be asked?

    Any help appreciated,

    Fred

     

    You don't have to use VS6. You can use VS 2003 or VS 2005 which support mixed debugging and stepping through interop. Right-click on the Web site node in the solution explorer, choose Properties and then Start Options. Check 'Native code' in addition to the ASP.NET debugger. This way you should be able to step into the C++ code directly from ASP.NET code.

    Question: why you are not using VS 2003/2005 C++? You can add C++ project to the same solution as the Web site and consume C++ project outputs in the Web site bin folder.


    Thanks
     
    <script src="http://www.asp.net/Avatar/default.ashx?u=fyale&i=1197760" type=text/javascript></script>

  •  

     

  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 27, 2007 3:18 AM
  • User743145481 posted

    Do you have the C++ code for GetTitle? What is the exception that is happening? Memory violation? Something else?

    If it works some times, then it is the C++ code at fault.  If you have the C++ code, then debugging the C++ code will be a lot easier even if it means just someone reading it (again, you should try to use a console or some other C++ app to debug it natively).

    By the way, you can pass the 5000 as sbTitleResult.Capacity:

    GetTitle(strParserResult, strParserResult.Length, sbTitleResult, sbTitleResult.Capacity);

    That way if you needed to pass the StringBuilder from some other function, you could determine the buffer size.

    Saturday, April 28, 2007 1:41 AM
  • User-1718610407 posted

    "you can pass the 5000 as sbTitleResult.Capacity"

    Thanks for your suggestions, picky.

    Sunday, April 29, 2007 6:20 AM
  • User-1718610407 posted

     

    [:D]

    Just now, someone has helped me solved the problem of debugging C++ DLL in ASP.net,

    Now I can step into and trace.

    Now we can make a conclusion that C++ DLL can be debugged in ASP.net.

     

    Thanks all for your help!   ^_^

     

    Sunday, April 29, 2007 9:17 AM