My question is that how can we debug a .dll script written in C#?
I have created a .dll for an .exe program and I am getting error and I want to debug it but enable to do so. I can easily debug a standalone program but don't know how to debug script for other program.
The program is full screen application (it is a PC game). And I am using SharpDevelop IDE (no plugin installed yet, pure vanilla as downloaded from main site)
And yeah I want to tell you that I am not doing anything like stealing game or something like that which can hurt game developer piracy. Just modding for personal use and it is allowed by developer for single player mode.
Maybe that all information you need. I am sorry for my bad English, this is my first question in stack overflow and I am not very genius, just learning C#.
And thank you.
First of all C# is not a Scripting Language since it's compiled to CIL and not Interpreted during runtime like python does.
In order to debug a .dll or an .exe you need few things in addition to the debugger itself:
A source code file.
A .PDB file matching to the .exe/.dll and the source.
Both things can be manually generated if you don't have them using Reflector or DotPeek and probably other programs.
Debugging for external processes in Visual Studio is possible by:
Attach to process (CTRL+ALT+P in Visual Studio) for a running process.
Start Extrnal Program in the project properties' Debug section.
Setting a specific flag in the registry using corflags or manually.
Using remote debugger if have to.
You can search about every one of them a lot since it is really an infinite topic but I hope you get the basic ideas from the answer, feel free to ask if not.
Have you tried "Attach to process"?
In SharpDevelop I believe the steps are (don't have it installed on this machine):
Run the exe and then al+tab out
Navigate in top menu to Debug > Attach to process...
In the window that appears find the running process of the exe and click Attach
If you are looking to decompile check out this question: How do I decompile a .dll file?
Related
So it's basically as stated in the title. I've created a WPF app in Visual Studio 2013 using some external libraries.
Application works flawlessly on my Development machine (Windows 8.1 x64 + Visual Studio 2013) but doesn't run at all on Production device (Tablet with Windows 8 (NOT 8.1)). App is developed under .NET 4.5, doesn't matter if I try to run Debug or Release version. The proccess just hangs a while and then closes without any errors or messages.
If anyone would know what to do or how to fix this I would be very happy.
Thanks in advance :).
The first thing too look up in this situation, would be the Windows event log. When a .NET application crashes badly, the .NET Runtime will log an event there.
Most of the time, these events will log the stack trace which lead to the crash. This will give you a hint as to what happened.
Such logs are found in the "Application" category, and the source name you need to look for is ".NET Runtime". Usually, there will be another entry with the source name "Application Error", but this one is much less likely to help you.
Another useful technique, is to add a Console.WriteLine call at the start of your program, in order to see if that line gets to run at all.
Depending on what you find using these techniques, you may also want to use tools such as Dependency Walker or ILSpy, as suggested by Mike Dinescu.
Most likely a binding error occurs at start-up but the production machine you're testing on is configured to silently report these errors and it doesn't display the typical dialog box that would inform you that the process crashed.
Don't fret though, that message would probably not help you too much anyway.
What you need to do is inspect the main executable with a tool that can generate a dependency tree and figure out which DLLs are missing. Most likely these will be native binaries, not managed. The usual suspects are the VC runtime, or MFC or ATL libraries but there could be others too. That's why you need to use a tool such as DependencyWalker or RedGate's Reflector to find all dependencies for the main executable.
It is because your external libraries are not compiled into final .exe file. So you either need to include them in the same folder or merge them into exe but this process can be quite tricky. Look for ILMerge. However it is way easier to just copy them with your exe file.
I'm trying to debug an application built in Visual Studio C# under MonoDevelop in Linux.
I have the source code, so I followed instructions that appears at Icaza's blog at http://tirania.org/blog/archive/2010/Feb-20.html without success (which basically consists on create an empty solution and set the Execute command to the already compiled application)
The application is executing correctly but when I load the source code file, and set a breakpoint, it never stops.
pdb's were also transformed to mdb's using pdb2mdb command.
What am I missing?
BTW, load source code into Monodevelop and build the application under Linux is not an option right now, due to the big size of the application and lots of tweaks in the build process. Just wanted to debug the compiled assembly.
There is a command line utility for soft debugger, have a look it, this might be what you are looking for.
I have an application I made that I lost the source code for, but the application has worked on my Win 2K computer. Now when moving to a Windows 7 computer it won't start. Probably some dependencies that needs to be solved, but I don't know which. The only error I got is a System.InvalidOperation without further description
Is there any tools(free) that I can use to get more specific information on what goes on
I am not sure how/if you can debug the application, but here is another idea.
There are tool out there called "reflectors", which allow you to look inside the .NET dll or executable.
They basically do the reverse of the compiler convert the dll/exe to source code (Now it won't be exactly the code you wrote, for example some local variables might have changed their names and some things might have been optimized, but the end result is the same, since this reflected code came from the same dll/exe.)
Now you can take the output of this and use it to rebuild and then debug your application.
Here are some ofthese tool:
dotPeek - free
.NET Reflector - not free
I know dotPeek doesn't allow you to debug inside of it, so you have to rebuild your application. The other one seems to be able to do that with its most expensive licence. Good luck!
You can also use Microsoft Debugging Tools for Windows (WinDbg). Here is an article that can help you.
http://www.dependencywalker.com/ will tell you dependencies and missing ones.
Also, you can attach visual studio, or get visual studio to launch a exe in debug mode without the source code.
my first try would be dependency walker just to make sure your not
missing some piece of native code
then I would look to just attempting to attach the program to visual
studio.
My next step would be to use something like reflector to get some
version of source code.
The pro version of regate's reflector let's you debug an existing dll without the sourcecode, costs $ 138 tho.
Ilspy will let you see the source for free, maybe you can figure it out from that.
Rgds Gert-JAn
I have a c# class library that I am calling from Classic ASP.
Is it possible to debug this using visual studio? Break points in the class don't work, which isn't surprising.
I am running this on iis7 in the browser, rather than through Visual Studio 2010 because of the fact that I'm using a classic ASP page. Do I need to get this running in Visual Studio in order for this to work?
I also tried to use Response.writes, but they result in:
The name 'Response' does not exist in the current context
You need to attach the debugger to the process (either IIS or another debugger that you are using to debug your classic ASP application) that is loading the assembly.
Under VS2010 go to Tools -> Attach to Process (probably the same under 2008 as well).
try to add in the code of the lib: System.Diagnostics.Debugger.Break(); where you want to break. Also ensure the lib is compiled and deployed with the pdb symbols. When the code will reach the instruction, IIS will throw an exception. The system will ask you to attach a debugger, and you're on the way.
I actually wrote an article regarding this:
http://www.jameswiseman.com/blog/tag/visual-studio-2010/
From the article:
Open Visual Studio 2010
This is easy enough if you have it installed. Might be a bit tricky if you don’t ;-)
Open your website in Visual Studio
Again, easy enough.
Fire up your web site.
I.e. open your browser and navigate to the website.
In Visual Studio, click ‘Debug’ Menu -> ‘Attach to process’
You may need to tick the box labelled ‘Show processes from all users’
‘Inetinfo.exe‘ if application protection is low or ”dllhost.exe‘ if application protection is higher. You may get an ‘Attach Security Warning’ popup. If so, continue On. It’s a bit scary at first, but if it’s your own app on your own PC, then you’ll be ok.
If you’re worried about this, follow the advice on MSDN.
Add a breakpoint to your code, and navigate to a location where you will hit it.
Troubleshooting - Registering pdm.dll
This worked on the first occasion that I tried it. Subsequent attempts were not so successful, and I found a few things that I had to do.
When trying to attach to ‘Script Code’ I got the following warning in the IDE.
Warning: Cannot debug script code. The
correct version of pdm.dll is not
registered. Repair your Visual Studio
2010 installation, or run
‘regsvr32.exe
“%CommonProgramFiles%\Microsoft
Shared\VS7Debug\pdm.dll”‘.
Just follow these instructions.
Troubleshooting - Restart IIS
This also helped on one occasion. Can’t really say why.
You will make your life much easier all round if you wrap you .net classes in a web service then call the web service from the classic asp pages.
For debugging, attach the debugger to the process as described in other answers.
For tracing, I find very handy the combination between System.Diagnostics.Trace.Writeline() in the class library and an OutputDebugString listener like DebugView.
I need to compare few function calls and signature between my application and an working application. Here I don't mean any way to reverse engineer or access the source code of the other application , but truly need to know what are the methods , Interfaces used by the working application.
I tried attaching my application to Visual Studio and then , Start>Debug , but this doesn't provide any useful information. Any help.
Reflector Pro Visual Studio plug in can debug not only exe you write, but any other assembly ;)
you can debug code, but once its compiled, its machine language and a debugger in Visual Studio is not going to do anything at all.
In order to get an idea of what a compiled executable is doing, you can use a program like this: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Runtime Flow (developed by me) can show all method calls in the working .NET application without need for source code.
Couple of solutions that I can think of:
Attach the exe with VS IDE Debugger, and use PDB files to debug the exe
Use Reflector to point towards your exe, and check the source. See example.