Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write to Visual Studio 2010 debug output window from Silverlight?

I am trying to get my Silverlight application to write to the Output/Debug window in Visual Studio 2010.

I've tried System.Diagnostics.Debug.WriteLine, and System.Diagnostics.Debugger.Log, both of which seem to promise to write output to this window when the VS 2010 debugger is attached to the process.

I attach VS 2010 to the iexplore.exe hosting the Silverlight app in Silverlight mode, but I have yet to see any of the output I am trying to log. I do see log messages for other things happening in the application; exceptions thrown, modules loaded, thread deaths, binding errors. What do I need to do in the Silverlight app to log to the same place?

I guess my alternative is to log to a global StringBuilder and break the process in the debugger and examine that, but that is much less convenient than looking at the information as it is logged in real time.

like image 921
antlersoft Avatar asked Jun 20 '12 18:06

antlersoft


People also ask

How do I write to output window in Visual Studio?

You can write run-time messages to the Output window using the Debug class or the Trace class, which are part of the System. Diagnostics class library. Use the Debug class if you only want output in the Debug version of your program. Use the Trace class if you want output in both the Debug and Release versions.

How do I debug a Silverlight project?

Right click on Silverlight project and select Debug tab from the project properties. Select "Out-of-browser application" radio button to enable Out of Browser debugging. Right click on Silverlight project and select "Set as Startup project". Once all configurations are completed run this application.

How do I show debug output in Visual Studio?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.


1 Answers

System.Diagnostics.Debug.WriteLine does indeed do what you're asking. I would check several things.

Make sure:

  1. You're attached to the right iexplore.exe process. Multiple iexplore.exe processes are launched, not just one.
  2. Your host project is set to debug Silverlight. This is an option in the project properties of the host project.
  3. If you set a breakpoint in your code that it does indeed break - if the code runs but the breakpoint isn't hit then you've attached using the wrong version of the code.
  4. "Show output from:" in the output window of visual studio is set to "Debug"
  5. If you right-click in the Output Window, ensure that "Program Output" is checked in addition to the other messages.
like image 187
McAden Avatar answered Sep 20 '22 11:09

McAden