473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

inconsistent accessibility error

Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but not
the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"
Nov 25 '05 #1
5 27226
C can't see E simply because E does not subclass C - it is *embedded* in it;
protected items are only available to sub-classes.

Possible fixes:
Move E to inside C
Make E public - it is only an enum after all
(possibly something involving making E internal protected and C internal,
but that has it's own limitations)

Hope that helps,

Marc

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but
not the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"

Nov 25 '05 #2
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper

Marc

"Marc Gravell" <mg******@rm.com> wrote in message
news:e3**************@TK2MSFTNGP14.phx.gbl...
C can't see E simply because E does not subclass C - it is *embedded* in
it; protected items are only available to sub-classes.

Possible fixes:
Move E to inside C
Make E public - it is only an enum after all
(possibly something involving making E internal protected and C internal,
but that has it's own limitations)

Hope that helps,

Marc

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but
not the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"


Nov 25 '05 #3
Andy Fish <aj****@blueyonder.co.uk> wrote:
Consider the following code fragment

public class Wrapper {
protected enum E { IN, OUT };
public class C {
protected void foo(E e) { }
}
}

I want the class C to be accessible from outside the wrapper class, but not
the method foo. Compiling this gives the error:

Inconsistent accessibility: parameter type Wrapper.E' is less accessible
than method Wrapper.C.foo

but the accessibility of both types is "protected"


Consider the following:

public class Subclass extends C
{
public void Something()
{
foo(????);
}
}

foo is accessible here, but E isn't. Hence the error.

Does foo definitely need to be protected rather than private?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '05 #4
Marc Gravell <mg******@rm.com> wrote:
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper


No, C can definitely see E due to being nested within T. See section
10.5.2 of the spec (ECMA numbering):

<quote>
The accessibility domain of a nested member M declared in a type T
within a program P, is defined as follows (noting that M itself may
possibly be a type):

[...]
If the declared accessibility of M is protected, let D be the union of
the program text of T and the program text of any type derived from T.
</quote>

Now, in our case, C is within the program text of Wrapper, so it has
access to E.

The problem is that things which may logically be able to call foo (by
deriving from C) wouldn't have access to E.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 25 '05 #5
Fair enough! Learn something new every day...

;-p

Marc

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Marc Gravell <mg******@rm.com> wrote:
Sorry - I mean't:
C can't see E simply because C does not subclass
Wrapper, and E is defined (protected) in Wrapper


No, C can definitely see E due to being nested within T. See section
10.5.2 of the spec (ECMA numbering):

<quote>
The accessibility domain of a nested member M declared in a type T
within a program P, is defined as follows (noting that M itself may
possibly be a type):

[...]
If the declared accessibility of M is protected, let D be the union of
the program text of T and the program text of any type derived from T.
</quote>

Now, in our case, C is within the program text of Wrapper, so it has
access to E.

The problem is that things which may logically be able to call foo (by
deriving from C) wouldn't have access to E.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 28 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ryan | last post by:
I get an error every so often with a DTS package on SQL 7. Error as follows. The connection is currently being used by a task. The connection cannot be closed or re-used. This doesn't happen...
4
by: Steven Quail | last post by:
Hi to all, I am trying to get the hang of using interfaces and for some reason I am getting the "inconsistent accessibility where property ... is less accessible than property ...(cs0052)". ...
1
by: Sunit Joshi | last post by:
I get this message "Inconsistent accessibility: return type 'TimeTracker.TrackerObjects.Project' is less accessible than method 'TimeTracker.TrackerObjects.GetProject(int)'" Here's the code...
3
by: AAV | last post by:
what is wrong with the code i get 'Error 1 Inconsistent accessibility: parameter type 'ConsoleApplication1.Garage.CarDelegate' is less accessible than method...
0
by: mariano774 | last post by:
Hello, I'm building a POC architecture framework, in which I have my business objects (BOs) made of internal classes and my transfer objects (TOs) made of public classes. what I'd like to do is...
3
by: WillyL | last post by:
I keep getting the following error message: Inconsistent accessibility: return type 'System.Collections.Generic.IEnumerable<Iteraties.Aandeel>' is less accessible than method...
1
by: bachyen | last post by:
I have the following code, but it is error when I build it. Can you help me? Can you tell me more about 'Inconsistent accessibility: return type', 'Inconsistent accessibility: parameter type'. ...
3
by: EvilProject | last post by:
While working on a scripting engine I Encountered the following problem. First I Created an abstract base class EPType that represent a variable type in the script. internal abstract class...
9
by: dylan.miller | last post by:
I'm having trouble understanding the internal access modifier. There are many classes in my assembly that should not be accessible outside of the assembly. I've used the internal access modifier...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.