ICollection default accessor

Discussion in 'ASP .Net Web Services' started by Dale, Nov 21, 2006.

  1. Dale

    Dale Guest

    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

    --
    Dale Preston
    MCAD C#
    MCSE, MCDBA
    Dale, Nov 21, 2006
    #1
    1. Advertising

  2. 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.
    Steven Cheng[MSFT], Nov 22, 2006
    #2
    1. Advertising

  3. Dale

    Dale Guest

    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[MSFT]" wrote:

    > 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.
    >
    >
    Dale, Nov 22, 2006
    #3
  4. 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.
    Steven Cheng[MSFT], Nov 23, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Janus Knudsen

    method type ICollection returns Dataview

    Janus Knudsen, Jul 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,827
    Natty Gur
    Jul 6, 2004
  2. HP
    Replies:
    1
    Views:
    1,600
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Feb 26, 2005
  3. Pinkesh
    Replies:
    0
    Views:
    325
    Pinkesh
    Jan 12, 2007
  4. Polaris431
    Replies:
    2
    Views:
    482
    Chris Dollin
    Nov 9, 2006
  5. =?Utf-8?B?TG9nZ2Vy?=

    ICollection List and IList

    =?Utf-8?B?TG9nZ2Vy?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    6,453
    mark4asp
    Jul 14, 2007
Loading...

Share This Page