From: Tom Shelton on
After serious thinking Mayayana wrote :
>
> --
> --
> "Davej" <galt_57(a)hotmail.com> wrote in message
> news:50bb2763-325a-40db-aca2-d531f91e2244(a)e1g2000yqe.googlegroups.com...
> On May 13, 2:19 pm, Tom Shelton <tom_shel...(a)comcast.invalid> wrote:
>>
>> You still did not provide information about the file... What kind of
>> content is it? Further - what line does the exception occur on?
>> Also, you said your getting an ArgumentException - that is documented
>> to be thrown when the bytes or char represents a unicode surrogate
>> pair.
>>
>
> Oh, I want to be able to read any file. I am old, from the ancient
> times when a binary reader reading byte by byte could read any file.
> Thanks.
>>
>
> :)
>
> Maybe this helps?
> http://msdn.microsoft.com/en-us/library/system.io.binaryreader.readbytes.aspx
>
> It refers to a ReadByte method. Your code seems to be
> reading characters. Oddly, though, the link above also
> mentions the ArgumentException error in connection with
> surrogate pairs, even in the context of bytes. It mentions
> a "unicode decoder". I don't know whether that's a misprint
> or whether .Net truly can't just read bytes without any funny
> business.
>
> I'm no .Net expert, but you seem to be getting answers
> to everything but the question you asked, so I too pity.

Well, there is reason I've not been answering. I've been trying to get
this guy to learn how to post a question that can be answered. Showing
up and saying "Hey, BinaryReader is throwing and exception, help!"
doesn't do the op or those of us trying to help any good at all...

I expect, like Patrice, that the exception is actually being thrown on
the PeekChars method. But, the op has thus far been reluctant to
provide clear information about the exception, what line it occurs on,
the nature of the data, and what he is actually trying to accomplish.
From the small snipit of non-working code it appears he is trying to
get the file length - but, I in fact htink that he is just
experiementing reading the bytes of a file. In that case, he should
just use the FileStream directly without the BinaryReader. Since the
FileStream will be a true stream of bytes. The OP is not using the
BinaryReader correctly, which is why he is getting the exception...

--
Tom Shelton