ICollection default accessor

D

Dale

I am returning a custom collection from a web service in .Net 2.0. When I
try to create a WebReference to that web service in the designer, I get the
following error:

You must implement a default accessor on AccountingBL.ProductCollection
because it inherits from ICollection.

I have no idea what they mean by default accessor. Any thoughts?

Thanks,

Dale
 
S

Steven Cheng[MSFT]

Hello Dale,

As for the "default accessor", it means the default propety that used to
access the item in a collection based on index key. e.g. In the following
custom collection class, the " public Int16 this[int index]" property is
the default accessor:

=====================
public class Int16Collection : CollectionBase
{
public Int16Collection()
{

}

public Int16 this[int index]
{
get
{
return ((Int16)List[index]);
}
set
{
List[index] = value;
}
}

public int Add(Int16 value)
{
return (List.Add(value));
}

.............................
========================

Are you using VB.NET or C#, if convenient, would you also provide the
complete custom collection class code here or a simplified test class which
also suffer the problem?

Based on my research, there are some one who suffer the same issue, and
mostly are in webservice or other XML Serialization scenario. You can
verify the above default accessor and also add a default constructor(no
parameter constructor) for your custom collection class to see whether it
helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

Dale

Steven,

Thanks for your help. The this[int index] indexer solved the problem. I
had an indexer in the form of this[object obj] which also handled obj if it
was an int. That's why I couldn't figure out the "default accessor"
statement in the exception. Now I know the difference between the two forms.

Just FYI, I am using C#. The collection class I am using is based on Natty
Gur's blog article at
http://weblogs.asp.net/ngur/articles/144770.aspx.

I have been using collection classes based on that since he first published
the article over 2 years ago. Until now, I have never run into this problem
but this is the first time I am returning the custom collection from a web
service rather than simply return an array of my objects from the web service.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA


Steven Cheng said:
Hello Dale,

As for the "default accessor", it means the default propety that used to
access the item in a collection based on index key. e.g. In the following
custom collection class, the " public Int16 this[int index]" property is
the default accessor:

=====================
public class Int16Collection : CollectionBase
{
public Int16Collection()
{

}

public Int16 this[int index]
{
get
{
return ((Int16)List[index]);
}
set
{
List[index] = value;
}
}

public int Add(Int16 value)
{
return (List.Add(value));
}

.............................
========================

Are you using VB.NET or C#, if convenient, would you also provide the
complete custom collection class code here or a simplified test class which
also suffer the problem?

Based on my research, there are some one who suffer the same issue, and
mostly are in webservice or other XML Serialization scenario. You can
verify the above default accessor and also add a default constructor(no
parameter constructor) for your custom collection class to see whether it
helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your reply Dale,

Yes, some problem won't occur until being in a particular context. For
example, the custom collection issue here only occurs in XML Serialization
context. Anyway, glad that you've got it working now.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top