mail-archives/mono-bugs/2010-October/104387.html

176 строки
5.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-bugs] [Bug 643379] New: NameValueConfigurationCollection.AllKeys uses contravariant array cast
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%20643379%5D%20New%3A%0A%20NameValueConfigurationCollection.AllKeys%20uses%20contravariant%20array%20cast&In-Reply-To=">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="105535.html">
<LINK REL="Next" HREF="104388.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-bugs] [Bug 643379] New: NameValueConfigurationCollection.AllKeys uses contravariant array cast</H1>
<B>bugzilla_noreply at novell.com</B>
<A HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%20643379%5D%20New%3A%0A%20NameValueConfigurationCollection.AllKeys%20uses%20contravariant%20array%20cast&In-Reply-To="
TITLE="[Mono-bugs] [Bug 643379] New: NameValueConfigurationCollection.AllKeys uses contravariant array cast">bugzilla_noreply at novell.com
</A><BR>
<I>Sun Oct 3 06:16:00 EDT 2010</I>
<P><UL>
<LI>Previous message: <A HREF="105535.html">[Mono-bugs] [Bug 643377] EqualityComparer&lt;T&gt; Attempts to JIT compile when deployed to the device
</A></li>
<LI>Next message: <A HREF="104388.html">[Mono-bugs] [Bug 635782] Serialization / De-serialization
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#104387">[ date ]</a>
<a href="thread.html#104387">[ thread ]</a>
<a href="subject.html#104387">[ subject ]</a>
<a href="author.html#104387">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>
<A HREF="https://bugzilla.novell.com/show_bug.cgi?id=643379">https://bugzilla.novell.com/show_bug.cgi?id=643379</A>
<A HREF="https://bugzilla.novell.com/show_bug.cgi?id=643379#c0">https://bugzilla.novell.com/show_bug.cgi?id=643379#c0</A>
Summary: NameValueConfigurationCollection.AllKeys uses
contravariant array cast
Classification: Mono
Product: Mono: Class Libraries
Version: SVN
Platform: x86-64
OS/Version: Ubuntu
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at lists.ximian.com</A>
ReportedBy: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">Novell at meinersbur.de</A>
QAContact: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at lists.ximian.com</A>
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.10)
Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10
The property System.Configuration.NameValueConfigurationCollection.AllKeys
always throws InvalidCastException.
Example program:
using System.Configuration;
class Test {
public static void Main(string[] arg) {
var conf = new NameValueConfigurationCollection();
var dummy = conf.AllKeys;
}
}
Reproducible: Always
Steps to Reproduce:
1. gmcs test.cs -r:System.Configuration
2. mono Test.exe
Actual Results:
System.InvalidCastException: Cannot cast from source type to destination type.
Expected Results:
Program ends without exception
Error is in NameValueConfigurationCollection.cs:
public string[] AllKeys {
get {
return (string[]) BaseGetAllKeys();
}
}
where BaseGetAllKeys() returns an object[]. Since arrays in C# are covariant,
but not contravariant, this throws an InvalidCastException. Using latest git
checkout (2nd Oct) on Ubuntu Lucid.
Changing to
public string[] AllKeys {
get {
object[] objArr = BaseGetAllKeys();
string[] result = new string[objArr.Length];
for (int i=0; i&lt;objArr.Length-1; i++)
result[i] = objArr[i].ToString();
return result;
}
}
yields the expected result. This might not be the best implementation.
--
Configure bugmail: <A HREF="https://bugzilla.novell.com/userprefs.cgi?tab=email">https://bugzilla.novell.com/userprefs.cgi?tab=email</A>
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="105535.html">[Mono-bugs] [Bug 643377] EqualityComparer&lt;T&gt; Attempts to JIT compile when deployed to the device
</A></li>
<LI>Next message: <A HREF="104388.html">[Mono-bugs] [Bug 635782] Serialization / De-serialization
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#104387">[ date ]</a>
<a href="thread.html#104387">[ thread ]</a>
<a href="subject.html#104387">[ subject ]</a>
<a href="author.html#104387">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/mono-bugs">More information about the mono-bugs
mailing list</a><br>
</body></html>