Reputation: 14971
I'm trying to see the output of a foreach loop in my code in the output window in an ASP.NET web app, but I don't get any results even though there is valid data. I've done a fair amount searching using Google with this issue, but nothing I've done works. Here is the code in my ASPX page:
List<MyClass> myClasses = GetMyClasses();
foreach (MyClass myClass in myClasses)
{
Debug.WriteLine(myClass.SomeProperty);
}
The code is very straight-forward. When I debug this page, myClass.SomeProperty has the value I want, but nothing is getting printed to the output window. What could I be missing? I cannot use a Response.Write because my Response stream is being used to create an Excel file. I also don't want to use Tracing.
I have this in my web.config file:
<system.web>
...
<compilation debug="true" targetFramework="4.0">
...
</system.web>
Upvotes: 5
Views: 2711
Reputation: 11
You are using System.Diagnostics.Trace, rather than the ASP.NET Tracing. To get System.Diagnostics.Trace working within ASP.NET see http://msdn.microsoft.com/en-us/library/b0ectfxd(v=vs.85).aspx.
Upvotes: 1
Reputation: 108800
(Sorry no full answer, but a bit long for a comment)
There are debug related features. (Related What does the optimize switch do)
What you need for your problem is the DEBUG
conditional. I guess the debug="true"
switch affects only the debug symbols but not the conditional.
edit:
hmm strange. scottgu states at http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx that debug="true"
should affect that conditional.
Note that the value of debug in a web app is driven by the value of the value in your web.config file.
Upvotes: 1
Reputation: 2200
Have you set
<system.web> <compilation debug="true" defaultLanguage="c#" /> </system.web>
in your web.config?
Upvotes: 0
Reputation: 1118
I also had a same issue but later found out that Debug.Writeline() didn't work with my unit tests.
Upvotes: 0