[Mono-dev] System.Collections.Generic.Dictionary.CopyTo inaccessible due to protection level

Alan McGovern alan.mcgovern at gmail.com
Sun Nov 25 08:14:20 EST 2007


Thats invalid code. If you want to access the 'CopyTo' method, you have to
cast the dictionary<string, object> as an ICollection<KeyValuePair<string,
object>>.

Alan.


> *Sigh*. Let this test program demonstrate:
>
> alankila at zeus:~/mono-hacks% gmcs bug.cs -o bug.exe
> warning CS8029: Compatibility: Use -out:FILE instead of --output FILE or
> -o FILE
> bug.cs(9,11): error CS0122:
> `System.Collections.Generic.Dictionary<string,object>.CopyTo(
> System.Collections.Generic.KeyValuePair<string,object>[],
> int)' is inaccessible due to its protection level
> /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to
> previous error)
> Compilation failed: 1 error(s), 1 warnings
> zsh: exit 1     gmcs bug.cs -o bug.exe
> alankila at zeus:~/mono-hacks% cat bug.cs
> using System;
> using System.Collections.Generic;
>
> class proggie {
>    public static void Main(string[] args) {
>        Dictionary<string,object> x = new Dictionary<string, object>();
>        x["this"] = 0;
>        KeyValuePair<string,object>[] y = new
> KeyValuePair<string,object>[1];
>        x.CopyTo(y, 0);
>        Console.WriteLine("woohoo, copied {0} => {1}!", y[0].Key,
> y[0].Value);
>    }
> }
>
> But on my SVN version of mono, I have added the public modifier and the
> code becomes suddenly runnable.
>
> --
> Antti
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071125/0f2eedbe/attachment.html 


More information about the Mono-devel-list mailing list