First time with this error - Inconsistent accessib

2020-04-10 23:30发布

问题:

This is my first time working with interfaces and proper namespace structure. When I compile I get the error below, I have no idea what it means. Any searches I do shows up private public issues but both are public. Any ideas?

Error Inconsistent accessibility: return type 'System.Collections.Generic.List' is less accessible than method 'Webtext.ApplicationEntities.Implementations.AdditionalEntities.UrlBuilderO2.GetUrlRequests (string, string, string, string)' C:\Users\Laptop\documents\visual studio 2010\Projects\Webtext\Webtext\ApplicationEntities\Implementations\AdditionalEntities\UrlBuilderO2.cs 19 39 Webtext

The Code files are:

namespace Webtext.ApplicationEntities.Interfaces
{
    interface IUrlBuilder
    {
       List<IOperatorRequest> GetUrlRequests(string UserName, string Password, string MessageRecipient, string Message);
    }
}

And:

namespace Webtext.ApplicationEntities.Implementations.AdditionalEntities
{
    public class UrlBuilderO2: IUrlBuilder
    {

        public List<IOperatorRequest> GetUrlRequests(string UserName, string Password, string MessageRecipient, string Message)
        {
            throw new NotImplementedException();
        }
    }
}

Namespace Structure

Webtext

ApplicationEntities

     Interfaces
          ##### INTERFACE IS HERE

     Implementations

          AdditionalEntities
               ##### URL BUILDER IS HERE

回答1:

You have a public property on a public class that exposes a list of non-public types.
You need to change IOperatorRequest to be public or change the UrlBuilderO2 class or GetUrlReuests method to be non-public.



回答2:

The problem is IOperatorRequest is probably internal.

UPDATE

What I said is correct. Omitting modifier makes it internal.

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.



回答3:

IOperatorRequest is internal which is less accessible than public.

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

from MSDN