Hi I have been working on a c# application which invokes a dll function. the dll is c code which actually initializes sockets to read/write/manipulate data. dll is compiled with debug info. The problem is under some conditions the c# application pops up a message a saying MemoryAccessViolation in the dll, but does not show any more information. i am basi开发者_开发知识库cally a linux developer, so i want to know any mechanism to debug such an issues.
Within Visual Studio in the project properties, you can enable debugging of unmanaged code by clicking on the Debug
tab and choose that option (Enable unmanaged code debugging). In addition, you can tell the debugger to stop when an exception occurs in you unmanaged code by pressing <ctrl><alt>e
(or choosing that option under the Debug menu) to bring up the exceptions dialog.
In the Debug tab, set up unmanaged debugging.
If that doesn't help, it's probably quickest to debug it with WinDbg which should halt execution right on the memory access violation.
Problem is that the violation might be the result of an action that happened far earlier.
There might be better answers but the general route I'd take would be to:
Try and get it to cause the exception on demand. In other words determine what exact conditions cause the error. This might take some time.
Try and capture the exception at the point it happens in the C# code. If your lucky then this may at least lead you to the steps needed for repeating the problem in #1.
If I have access to change the dll written in c; add lots of logging. Hopefully you at least have an idea of where this is coming from.
Here is a forum post with some tips: http://social.msdn.microsoft.com/Forums/en/netfxcompact/thread/69e84750-6636-4656-bbd4-8d3586290af3
Launch your managed code as usual using VS debugger. Now you would need to launch second copy of VS and attach it to the process you're debugging. Select native code for this second debugger instance. Now assuming DLL is already loaded (anything from that DLL already executed) you should be able to set a break point.
Sometimes it helps to show message box in the native DLL so execution would stop at the point you're interested in and you can attach native debugger and continue.
精彩评论