How to debug server code
Options
Comments
-
Found out myself.
need to make server under .net 3.5, cus it is based on 2.0
and 4.0 is completely new one and cannot be run under 2.0 runtime.0 -
Yes, DotNet 4 compiled assemblies won't run in DotNet 3.5 runtime.
Visual Studio 2008 also only debugs up to DotNet runtime 3.5.
Glad you found it.0 -
In your Application class (the one that inherits Photon.SocketServer.Application) override Setup() method and add this line: System.Diagnostics.Debugger.Launch(); . When your server code will be launched you get a nice message box that will ask you if you want to attach the debugger. You can debug startup code this way!
__________________
Les Sacs Longchamps0 -
Boris wrote:This does actually work without the C++ project, too.
Sort of like Xeevis wrote, it was a bit different when I did it though:
project properties, debug page
1) start external program: bin_Win64\PhotonSocketServer.exe
2) command line arguments: /debug Instance1
3) working directory: \bin_Win64\
when using VS2008 make sure to set the CLRVersion to 2.0;
no need to add the exe to the solution.
I was just trying this but the debugger seems to just exit without any useful information? It starts running then stops a couple of seconds later with the following in the output window:
[code2=plain]The program '[10796] PhotonSocketServer.exe: Program Trace' has exited with code 0 (0x0).[/code2]
I am using Visual Studio 2012 btw
I'll try the manual System.Diagnostics.Debugger.Launch() method for now but it'd be great to get automatic attachment working0 -
Please check your logfiles, there should be a hint why it stopped. Or attach them here, and we can have a look.0
-
Boris wrote:Smilediver wrote:3. Attaching debugger automatically.
This one is my favorite, as it attaches the debugger by simply clicking F5 in Visual Studio. For this create a dummy empty C++ project in your solution. Add main.cpp and a stub for main(). Select it as startup project. Setup project dependencies that building this one will build your server too. Go to project properties and in Debugging tab change Command to where PhotonSocketServer.exe is located, for example: "e:\Projects\Photon\Server\deploy\bin_Win32\PhotonSocketServer.exe". For Attach choose Yes. Set Debugger Type to Managed Only (mixing with native kills the server after detaching debugger). And voila! Hit F5 and it will compile, update your server, and attach a debugger in just a couple seconds. :-) And you can debug startup code this way too!
Sort of like Xeevis wrote, it was a bit different when I did it though:
project properties, debug page
1) start external program: bin_Win64\PhotonSocketServer.exe
2) command line arguments: /debug Instance1
3) working directory: \bin_Win64\
when using VS2008 make sure to set the CLRVersion to 2.0;
no need to add the exe to the solution.
Hello, guys! I used this method to attach debugger to my Photon Server. When I start debugging my project VIsual Studio 2013 asks me to provide PhotonServer sources such as PeerBase.cs, ApplicationBase.cs. Without these files further debugging is impossible. How to fix it?0 -
Hi and welcome to our Photon forums
We don't release the source code for the Photon.SocketServer.dll (which includes the classes you mentioned above). You can not step into this code for debugging, and it is, in general, not neccessary. Just tell your debugger to step over these classes. If there is an exception in these classes, please send us a log file and we will have a look and fix the issue, or help you to resolve the problem.0 -
We prefer to log to a cloud-based log provider to debug server code (Loggly specifically - https://www.loggly.com/docs/net-logs/) because it's fast to implement and we can see the data show up immediately.
WHAT to log is a different story because unlike a debugger you have to think ahead a bit about what to log instead of stepping through the code with a debugger, but it gives you a ton more information about the conditions/steps that can lead to bugs.
If anyone's interested, I can give specifics about what/how we log.0 -
Not sure if the standard config file has changed recently, but I needed to use "/debug Default" instead of "/debug Instance1". I'm assuming that a name change happened in PhotonServer.config at some point.
Other than that, option 3 runs smoothly with VS 2013 Express.1 -
Hi,
The debuging work find but after a time, the service shutdown if i not stop debugging fast enough.
Is there a wait to say to photon to not stop my service even if it not response for debugging reason.
Best0 -
No way?0
-
"/debug Default" worked for me in Visual Studio Community 2015 . Great ThanksCBiz said:Not sure if the standard config file has changed recently, but I needed to use "/debug Default" instead of "/debug Instance1". I'm assuming that a name change happened in PhotonServer.config at some point.
Other than that, option 3 runs smoothly with VS 2013 Express.0 -
Can I debug server side code remotely from my local machine?0
-
hi, jesusgumbau
yes, this should be possible if you host your server your self. how to setup remote debugging is out of scope for this forum
best,
ilya0 -
Hello everyone. I'm really confused. Please guide me.
I am modifying the LoadBalancing project. I'm using Visual Studio Community 2015.
Should I be running PhotonControl? Should it not be running it? I wanna be able to see my logs on Visual Studio Console when I hit F5.
And how do I write debug logs? Should I use System.Console.WriteLine()?
Please help.0 -
0
-
http://imgur.com/a/bI4of
I also tried the default setting. Please see image.
When I hit F5, It gives me this message box. Hitting OK, stops the application.0 -
Now I'm getting a different message,Only one copy of "LoadBalancing" can run at a timePlease see image
The settings I used is also in the screenshot. I run this with and without PhotonControl.exe running. Same results.0 -
this last message happened with you because still one copy of Photon is running
just find it in task manager and stop
if you take unchanged version of photon sdk, and start msvs by clicking on LoadBalancing solution, then it will work out of the box. all path will be set correctly0 -
@chvetsov Thanks for clarifying that. The posts in this thread is a bit old; I thought I still needed to do some setup.
I am able to run the solution without any errors now. Now, I just need to be able to print to the console. I triedConsole.WriteLine()
but it doesn't work. I added breakpoints so I'm sure it is being called. How should I do it?0 -
we use log4net for logging.
you need just setup appender which logs to debug out put and that is it
best,
ilya0 -
Please REMOVE me from this thread. It's not bookmarked by me so I shouldn't get any notifications but they still arrive.
When I went to (this) new forum (where link points) I was asked to basically re-register (new name, new ToS but same e-mail) and this thread was NOT shown as bookmarked.
0 -
@chvetsov Can you elaborate? I don't understand what you mean by this:you need just setup appender which logs to debug out put and that is it
Do you have tutorials? Or code snippets? You make it sound so easy.1 -
please use google
best,
ilya0 -
System.Diagnostics.WriteLine()johnny_tictoc said:Hello everyone. I'm really confused. Please guide me.
I am modifying the LoadBalancing project. I'm using Visual Studio Community 2015.
Should I be running PhotonControl? Should it not be running it? I wanna be able to see my logs on Visual Studio Console when I hit F5.
And how do I write debug logs? Should I use System.Console.WriteLine()?
Please help.0 -
I'd like to share my approach which is similar to #3 just a bit simpler .
1. Open solution with your server app, set project's build path to correct one within Photon app
2. Right click solution > Add > Existing Project...
3. Choose PhotonSocketServer.exe
4. Right click and set it as startup project
5. Right click again and go to properties
5a. Set arguments to "/debug Instance1" without quotation
5b. Set debugger type to Managed
6. Hit F5 and you are rolling right from very first line of managed code 8-).
Note: as it runs completely under hood of Visual Studio when you stop debugging it will also stop server. If you want to run server outside and just attach to it, you can change "Attach = Yes" in step 5 properties.
i used this method.i can set breakpoints but my the debugger wont stop on the breakpoints.what is the problem??0 -
i changed the CLRversion to 2.but nothing happend yet0
-
oh. when i change CLRVersion the photon server cant be run
System.BadImageFormatException: Could not load file or assembly 'Photon.LoadBalancing' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.0