devforall
devforall

Reputation: 7337

StreamReader issue

if I put a debuger from starting line one of this code and step through i dont get anything event after the line

    xmlData = reader.ReadToEnd(); 

but if I have debugger on the last line of this code.. where the brace closes, I get everything. i dont know if this only the debuger acting crazy, or a real thing

using (StreamReader reader = new StreamReader(context.Request.InputStream))
{
    xmlData = reader.ReadToEnd();
}

Can anyone tell me whats going on. cause sometimes i am not able to get any data from streamreader, even though the data is sent correctly.

Thanks

Upvotes: 1

Views: 224

Answers (2)

Mark Byers
Mark Byers

Reputation: 838086

If you put a breakpoint on a line the break occurs before that line gets executed, so it's no surprise that you don't get any data.

But I suspect what you mean is that you place a breakpoint and then step through the code slowly until you reach the end and then check the contents of the variable and find that they are empty.

  • One cause could be a timing issue. It could be that the service you are reading from has timed out.
  • Another cause could be a race-condition in your code.
  • One other unexpected thing that can catch people out is that watches can cause side-effects and stepping through the code causes the watches to be re-evaluated. This can change the state of your program depending on where you put the break-point. You should be careful not to set up a watch on a property that has a side-effect when evaluated.

Upvotes: 1

ChrisLively
ChrisLively

Reputation: 88044

The reader isn't going to perform the actual "read" until the ReadToEnd method is called. What are you trying to do?

Upvotes: 5

Related Questions