5

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.

Update

I have this in my web.config file:

<system.web>
    ...
    <compilation debug="true" targetFramework="4.0">
    ...
</system.web>
1
  • So what was the problem/How did you fix it? Commented Jun 22, 2011 at 18:08

4 Answers 4

1

(Sorry no full answer, but a bit long for a comment)

There are debug related features. (Related What does the optimize switch do)

  • Generation of debug Symbols
  • C# IL optimization
  • Jitter Optimization
  • The DEBUG conditional define.

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

I also had a same issue but later found out that Debug.Writeline() didn't work with my unit tests.

1 Comment

This isn't for a unit test. This is for an ASP.NET web form page. I'm just trying to compare the output for a few foreach loops.
0

Have you set

<system.web> <compilation debug="true" defaultLanguage="c#" />  </system.web>

in your web.config?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.