PRB: "Ambiguous match found" Error Received When You Use the Default Collection Editor in Visual C# .NET (823194)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft ASP.NET (included with the .NET Framework 1.1)
SYMPTOMSYou create a Web server control in Microsoft Visual C# .NET
with a type-specific collection property and then put it on a Web page. When
you edit the properties of the default collection editor and switch from Source
view to Design view, or when you close and reopen the Web page, you may notice
the following error message: Parser Error: Ambiguous match
found. WORKAROUNDTo work around the problem that is described in the
"Symptoms" section of this article, modify the code of the ClassColl class that is described in the "More Information" section of this article. Replace this code: // This is the type-specific collection.
public class ClassColl : System.Collections.CollectionBase
{
public int Add(ClassObj obj) { return List.Add(obj); }
public void Insert(int index, ClassObj obj) { List.Insert(index, obj); }
public void Remove(ClassObj obj) { List.Remove(obj); }
public bool Contains(ClassObj obj) { return List.Contains(obj); }
public void CopyTo(ClassObj[] array, int index) { List.CopyTo(array, index); }
public int IndexOf(ClassObj obj)
{
foreach (ClassObj r in List) if (r.Equals(obj)) return List.IndexOf(r);
return -1;
}
public ClassObj this[int index]
{
get { return (ClassObj)List[index]; }
set { List[index] = value; }
}
public ClassObj this[string index]
{
get { return (ClassObj)List[IndexOf(new ClassObj(index))]; }
set { List[IndexOf(new ClassObj(index))] = value; }
}
} With this code: // This is the modified type-specific collection.
public class ClassColl : System.Collections.CollectionBase
{
public int Add(ClassObj obj) { return List.Add(obj); }
public void Insert(int index, ClassObj obj) { List.Insert(index, obj); }
public void Remove(ClassObj obj) { List.Remove(obj); }
public bool Contains(ClassObj obj) { return List.Contains(obj); }
public void CopyTo(ClassObj[] array, int index) { List.CopyTo(array, index); }
public int IndexOf(object obj)
{
if (obj is int)
return (int)obj;
if (obj is string)
{
for (int i = 0; i < List.Count; i++)
if (((ClassObj)List[i]).ObjectString == obj.ToString())
return i;
return -1;
}
else
{
throw new ArgumentException("Only a string or an integer is permitted for the indexer.");
}
}
public ClassObj this[object obj]
{
get { return (ClassObj)List[IndexOf(obj)]; }
set { List[IndexOf(obj)] = value;}
}
} STATUS This
behavior is by design.REFERENCESFor more information, visit the following Microsoft
Developer Network Web site: For
additional information, click the following article number to view the article
in the Microsoft Knowledge Base: 324301
HOW TO: Create a Web Control with an Expandable Property in the Designer by Using Visual C# .NET
Modification Type: | Major | Last Reviewed: | 8/6/2003 |
---|
Keywords: | kberrmsg kbCollectionClass kbWebServer kbprb KB823194 kbAudDeveloper |
---|
|