Debugging a third-party DLL in Visual Studio?

2019-01-18 21:18发布

I am using a third-party DLL. For some particular cases, a function in the DLL is throwing an exception. Is it possible to debug the DLL in the Visual Studio?

After the answer from Andrew Rollings, I am able to view the code, but is there any easy way to debug through the code in Visual Studio?

8条回答
Viruses.
2楼-- · 2019-01-18 21:29

I thought .NET Reflector got some debugging plugins. That'd be a so much better idea because decompiling and recompiling code generally fails, and you need to do so many changes in the code to fix it.

Give .NET Reflector debugger a try. It might help you a lot.

查看更多
beautiful°
3楼-- · 2019-01-18 21:41

If the DLL is in a .NET language, you can decompile it using a tool like .NET Reflector and then debug against the source code.

Or you could ask the vendor if source code is available. That's probably the easiest way.

查看更多
再贱就再见
4楼-- · 2019-01-18 21:41

Building on Andrew's answer, you just treat the decompiled source code as a new library within your project and set breakpoints in the source. Remove all references to the 3rd party DLL so that it is the decompiled code that is executing.

Other things:

  • You may be breaking the law by decompiling the code, or breaching a licensing agreement with the 3rd party vendor. Make sure to review this with someone.
  • You will want to make sure that you remove references to your decompiled version if you are shipping to other developers, or checking into a larger source tree. Easy to forget this!
查看更多
虎瘦雄心在
5楼-- · 2019-01-18 21:44

Something that has worked for me with debugging a couple of third-party libraries as well as .NET itself is WinDbg. It is an awesome debugger from Microsoft that I have used to troubleshoot some sticky problems that were occuring deep inside the framework.

You need to use the Son of Strike (SOS) extensions if it is a managed DLL. It can debug native also. You will need to know a bit about callstacks and assembly/CIL instructions to be good at using it. You should be able to determine the exception and what is causing it. We have used WinDbg/SOS to find for instance that in HttpWebResponse, if you are using Gzip compression to download a page and the server returns a bad Gzip header, .NET runs the decompression in the threadpool and a crash will take out your process. Happy debugging.

查看更多
做个烂人
6楼-- · 2019-01-18 21:50

As Cesar Reyes mentioned in Stack Overflow question Visual Studio - Attach source code to reference, ReSharper 5 (and later) has this capability.

查看更多
欢心
7楼-- · 2019-01-18 21:51

.NET Reflector 6 comes with a Visual Studio Addin that lets you use Visual Studio's step-through-debugging on assemblies that you don't have the source code for.

Have a look at this blog post:

http://www.simple-talk.com/community/blogs/alex/archive/2009/09/22/74919.aspx for more details.

This is still a very early build. So no guarantee that it'll work, and it might break your visual studio configuration or project configuration. Make sure you have backups (or source control) for any projects you use this on.

Download here: http://www.red-gate.com/MessageBoard/viewforum.php?f=109

查看更多
登录 后发表回答