3

i'm trying to return list of objects from a class and get the following error:

Error 1 Inconsistent accessibility: property type 'System.Collections.Generic.List<EventXmlExtract.Attribute>' is less accessible than property 'EventXmlExtract.EventExtract.AttributeList' C:\Documents and Settings\eyalk\My Documents\Visual Studio 2010\Projects\Blobs\EventExtractDll\EventExtract.cs 14 32 EventExtractDll

my code tries return _attributeList:

public class EventExtract
{
    private string _type;
    private int _type_id;
    private List<Attribute> _attributeList = new List<Attribute>();

    internal List<Attribute> AttributeList
    {
        get { return _attributeList; }
        set { _attributeList = value; }
    }
}

what is the problem ? and how can i retrieve the list ?

4
  • 2
    What is the class Attribute? I stronly suspect that it's not the System.Attribute class Commented Feb 28, 2011 at 13:30
  • then there's the problem. make that Attribute class at least 'internal' and the code will compile just fine Commented Feb 28, 2011 at 13:35
  • Could you please show it's definition, as that is the root cause of the problem. Commented Feb 28, 2011 at 13:35
  • I've just updated my answer below. Try it out and report back. Commented Feb 28, 2011 at 13:38

4 Answers 4

7

Make the class Attribute public or internal.

You can't return a list of objects where the class is private, because then the calling code can't access the objects.

Alternatively make the AttributeList as restricted as the Attribute class, if that is how you want it.

Sign up to request clarification or add additional context in comments.

1 Comment

Unless nested, classes can only be public or internal.
2

Your Attribute class lacks the required visibility.

change the class definition to either

public class Attribute
{

or

internal class Attribute 
{

2 Comments

Unless nested, those two are the only allowed access modifiers on a class element, anyway...
Makes you wonder how he ended up in that spot in the first place. For the default modifier is internal
0

I think the problem is that you have declared the property as private. Try making it as protected or public.

1 Comment

The property is not declared as private, it's internal. The problem is not that the property is too restricted, it's that the type that it returns is too restricted.
-1

Did you include the following?

using System; using System.Collections.Generic;

The class compiles fine on my box... :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.