I have a self-hosted WCF service. I don't have an app.config file, instead all the configurations are performed at run time in the code. But I cannot figure out how to enable debugging in the code.
UPDATE
I have a VS solution with two projects:
WCF service hosted in a WinForms application
Simple console client consuming the service
I'd like to be able to start the debugging session in Visual Studio, debug the client, set and hit breakpoints in the service application. I was able to do this when I used app.config files, but now I'd like to do the same without them.
Attach the debugger to the process that your wcf service is running in.
If in IIS you will have to attach to the corresponding w3p.exe process.
If in a stand alone app or windows service, attach to the name of your exe.
In VS in debugger option there is sub option "attach to process". You will need to set brak point to the appropriate code and call the service causing that code path to execute.
Can refer this link:
http://msdn.microsoft.com/en-us/library/aa702726.aspx
as well as this one:
http://www.codeproject.com/Articles/17258/Debugging-WCF-Apps
This might be helpful to you.
if you need to launch debugger from the code, write the following line:
System.Diagnostics.Debugger.Launch();
I often use this tecknique in debugging purpose. But it is better to remove it in release version.
If you want to attach to the already running process, open Visual studio, go to menu Debug > Attach to process, find the hosting process and click "Attach" button.
Related
Is it possible to simulate non-UserInteractive mode when debugging in Visual Studio, and if so, how?
I have a service that is running that I'd like to debug, but the behaviour is different depending on whether I'm debugging it or running the service.
I found this question:
How do I debug Windows services in Visual Studio?
The answer there doesn't quite do it for me because following that, when you debug it, the debugger runs the process in UserInteractive mode. What I want is the debugger to debug the process, but without UserInteractive mode.
For example, I had an error that was buried deep in the code because a library it uses was trying to display some sort of dialogue box (even though the dialogue box wasn't seen by the user). This would not be picked up in Debug because UserInteractive mode is used. I want to be able to do more debugging on these kinds of issues
To debug a service you would need to
Build your service in the Debug configuration
Install your service to see how to do this go to this link https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-install-and-uninstall-services
Start your service either from services control manager, server explorer or even from the code and if you want to know how to do this then go to this link https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-start-services
Start visual studio as admin so that you can attach to system processes.
Optional > on visual studio menu bar, choose Tools, Options. In the options dialog box choose debugging symbols and select microsoft symbol servers check box, and then choose the OK button
On the menu bar choose attach to process from the debug or tools menu for the short key press CTRL+ALT+P
The process dialog box appears
Then select the show process from all users check box
In the available process section, choose the process for your service and then choose attach
Hope this helps
I hate attaching to a process from Visual Studio. It works, but it also seems to take forever to build the list of processes to choose from. Perhaps that's because our systems are locked down too tightly. It's entirely possible that in a different environment, this works just fine.
Still, I find it much easier just to trigger a programmatic breakpoint when the service is starting and jump in to debugging at the beginning. To do this, call the following in the OnStart() callback:
System.Diagnostics.Debugger.Break();
When you start your service, you should get a prompt indicating an unhandled exception has occurred.
Click the Yes option, answer Yes to the UAC prompt, select which instance of Visual Studio you want to use, and then debug normally once Visual Studio starts.
When you're finished debugging, just stop the service, and the debugger will quit automatically. However, don't close that instance of Visual Studio. Make whatever changes you need to make the service, and rebuild it. Then when you restart the service and you get to the point of selecting the Visual Studio instance to use, it'll include your original debug instance in the list. It's much faster to jump back into that one than creating a new instance each time.
HTH
I have a web site project in Visual Studio that includes some web handlers. I have tried various ways to try and debug the web handler code, but when I set a breakpoint and start the project the breakpoint becomes a circle and the breakpoint will never get hit. I've tried using the option to not open a page when starting the project and I don't see either w3wp.exe or any process for aspnet so there isn't any task to attach to.
I don't see anything in web.config that registers the handler but when I look at how to register a handler I'm confused. Here is the line of code in the aspx page that invokes the handler...
http://localhost:13196/handler.ashx?id=4764806f-2abb-40b4-a5d9-3139fdb060c2
When they talk about registering the handler they talk about a file type. What is the file type in this case?
Thank you for any help that you can provide.
Gary
Make sure you're debugging the project off the latest build, set your break point and try hitting F5 (Debug -> Start Debugging). If its running off IIS, you can debug by going to Tools -> Attach to Process and the check "Show processes from all users" and w3wp.exe should be listed. Once you attach you might be prompted to launch VS as an admin where you'll have to go through the motions of attaching it again.
Pls don't mark it as duplicate .. bcoz I have seen all the solutions but nothing is working for my case..
I have two machines devMachine and serverMachine
in devMachine I am developing application with Visual Studio and Now I have a simple Console Application..my need is I need to run this Console Application in serverMachine and debug from devMachine via Remote Debugging.
As told in Microsoft document, I have installed Remote Debugging tool in serverMachine and set the Authentication mode as Native (No Authentication) and run the Console Application in serverMachine.
Now , I have attached the remote process in devMachine's Visual Studio. All are working fine
But only problem is breakpoint is not hitting in Visual Studio
Note: I have placed required .pdb file in serverMachine and set that .pdb file path in devMachine's Visual Studio (Tools->Option->Debugging->Symbols).
Can anyone help me to resolve this issue?
What does the error message on the breakpoints say (if you hover over the breakpoint) - that it's different from the source? --> You can try disabling (from Tools/Options/Debugging) - Enable source file to exactly match the original version
What does the Modules window say - do the PDB's appear as loaded? if not, have you tried loading them manually (from the Modules window, right click the PDB and load)? - Is there an error message if it fails?
--> you might be in a case where the source files in the local machine are different from the ones on the remote one. Try copying everything over and see if that works (PDBs would be in the same folder as the EXE)
There are two reasons for the remote debugger to not hit the breakpoint
Wrong symbols.
Using the wrong .Net framework while debugging ( you can select on the "attach to process" window in visual studio).
Don't attach and just set remote debugging on. Copy all the project files to the identically placed and named folder in the server during post-build.
I had an issue with Visual Studio not breaking at my breakpoints although it looked like everything was setup correctly for the remote debugger on an IIS machine. I searched everywhere for an answer. The issue finally presented itself when I tried to manually attach the VS debug to a process (VS menu --> Debug --> Attach to process...) For some reason, there were multiple processes for the same application pool (there should only be one process, not sure where the others came from) I logged into my IIS server and killed all the processes for my application pool and then restarted the IIS application. When I saw there was only one process for the app pool (as I expected), I tried debugging in Visual Studio and it attached to the correct process. It turns out that when there were multiple processes for the same application pool, it attached to the "wrong" one.
Looking at your screen shot, could it be simply because the break points are in the "main" function which could already have finished before you can attach the debugger?
Suggestion:
Maybe put some artificial wait/delay code of say 20 secs in "main" above the first break point to give yourself enough time to attach to the process before "main" completes.
I have seen this option under the debug menu, but I don't completely understand what it means. Could somebody explain it to me? Thank you in advance.
When you Attach to a Process, you're causing the debugger to attach to the process and allow you to set breakpoints within code that you have not started from a debugger. This is very useful in the situation of trying to debug things that have an automatic spawning process (such as .NET code that runs under IIS).
Instead of pressing F5 to start an instance of your app (or pressing the green "go" button), you can attach the debugger to an already running program. While you /can/ attach to an instance of Notepad, since Notepad is not a .net application and you don't have the .pdb debugging symbols for notepad, it won't do much good.
To attach to an already running instance of your program (or an internet explorer instance that is running your code)...
compile non-optimized
compile "Full" debugging symbols (the
default for the DEBUG configuration)
make sure the .pdb file is in
the same directory as the .dll or .exe (or you can find them manually)
make sure the code is in the same path as when it was compiled (or
you have to find it manually)
I don't know what the official documentation says, but this is how I use it.
If you are working in a project that runs continuously, say a web site deployed in IIS or a windows service and you have the solution with the code of the running program open in VS, you can attach to the process and debug it as if you had launched it hitting F5, set breakpoints, etc. It also allows to attach to a process running in a remote machine if it is properly configured, which turns out to be useful if you are debugging a process in a staging server or something like that.
You just need to make sure that the code you are editing is the one used to compile the binary.
You can attach the debugger to a running process and start debugging it where its at. Mostly useful only if you have the debugging information for the executable.
I tend to use it if my program hits an exception and I'm not already debugging it. I can attach and then view the variables and call stack.
That means to attach a debugger (i.e visual studio's integrated debugger) to the process so you can pause it and inspect variables at runtime. This happens when you hit F5 automatically, or can be done manually using the debug menu.
Question:
I've written a nHibernate API for a C# mailserver.
The mailserver you can find here if you're interested:
http://www.lumisoft.ee/lswww/download/downloads/MailServer/
And my (buggy) API here:
http://www.lumisoft.ee/Forum/default.aspx?g=posts&t=722
The thing is, the mailserver consists of several components:
net dll: all the lowlevel protocol stuff
MailServer exe: the mailserver itself
DB_API dll: the mailserver database plugin-API
Manager: the mailserver configuration manager
Now, my API works fine (meaning it doesn't crash, but not necessarely returning the correct results) in the console application where I tested it.
But when I plug it (nhibernate DB_API dll) into the server and use the Mailserver manager to just adjust the configuration settings somehow, I get null reference exceptions.
Now I need to debug the server by step through to see where exactly the error occurs.
Now, because it consists of multiple components (separate projects), I can't just use step through in visual studio...
How do I debug this?
I assume I need to attach the debugger to the process, but then?
You can set Visual Studio to start debugging multiple Projects at once. Just right-click on the solution in the project browser and bring up the preferences.
There you can find an entry called Startup Items or something similar.
I use it all the time when debugging client-server setups, works like a charm.