views:

26

answers:

1

I need to produce my own DecoderFallback and DecoderFallbackBuffer classes to implement some custom stream decoding.

I have found that the stream reader making use of it is calling GetNextChar() repeatedly even when my specilizaed DecoderFallbackBuffer.Remaining property returns 0 to indicate that there no more characters to return.

The end result is that the stream reader gets into an infinite loop.

Why is this happening?

A: 

The solution is to make one's GetNextChar() return (char)0 when the Remaining property is 0. This is definately not clear in the MSDN documentation.

I suspect that, internally, readers are doing something like

while (theChar = dfb.GetNextChar() <> 0){}

instead of

while (dfb.Remaining > 0){ theChar = dfb.GetNextChar(); }

Anyways, seems to work fine. Just wanted to contribute this clarification of using this .NET class to SO.

Canoehead