[Mono-dev] TextReader, TextWriter and IDisposable

Robert Jordan robertj at gmx.net
Sat Oct 21 11:56:53 EDT 2006

Leszek Ciesielski wrote:
> Hi,
> when I tested my vs2005 projects against xbuild, I found an annoying
> bug. My 2.0 code did not  compile. I attach a snippet, alongs with
> comments. It seems that 1.0 TextReader/Writer did not implement
> IDisposable (or implemented it explicitly), although I cannot find
> this info on msdn (there is only a note that their Dispose() methods
> are new in 2.0). However, as I compiled with gmcs, the error still
> arose:
> error CS0122: `System.IO.TextReader.Dispose(bool)' is inaccessible due
> to its protection level
> this time only with TextReader.
> First: it's a glitch in TextReader (it implements the interface
> explicitly, so the object is only disposable when cast to
> IDisposable), it's Dispose() implementation should be changed to this
> of TextWriter, this is also visible on class status pages.
> Second: isn't this also a small problem with the compiler? Why does it
> complain about Dispose(bool), when I only reference Dispose() in my
> code?

Because mcs first tries to lookup the method using
Type.GetMethod (string) (it's faster, because non overloaded
methods are far more probable).

In your sample it finds Dispose (bool) as the only method and
detects that the method has the wrong accessibility attributes,
so it gives up checking the arguments before emitting the
error message.

MS CSC behaves exactly like this, so it's probably not an error.


More information about the Mono-devel-list mailing list