Is the internal interface * less * accessible than the internal secure constructor?

I have an interface and an abstract base class defined in the same assembly:

IFoo.cs:

internal interface IFoo { ... } 

Base.cs:

 public abstract class Base { internal protected Base(IFoo foo) { ... } } 

This generates the following compiler error:

 CS0051: Inconsistent accessibility: parameter type 'IFoo' is less accessible than method 'Base.Base(IFoo)' 

If I create the constructor of the base class for internal use only, the error will disappear. Since the class is abstract, an access-protected addition is possible, does nothing ...

However, I do not understand the error. MSDN defines "protected internal" as

"Access is limited to the current assembly or types retrieved from the containing class"

How is the internal IFoo interface less accessible than the internal secure constructor?

+6
source share
1 answer

This MSDN page defined "protected internal" as (highlighting from the original):

Secure internal accessibility means secure OR internal, not secure AND internal. In other words, the protected internal member can be accessed from any class in the same assembly, including derived classes. To restrict access to only derived classes in the same assembly, declare the class itself internal and declare its members as protected.

In other words, types outside the current assembly obtained from Base would have access to Base(IFoo foo) , but they would not have access to IFoo, since it is internal. So the error.

+9
source

Source: https://habr.com/ru/post/950288/


All Articles