开发者

Inconsistent accessibility problem [duplicate]

开发者 https://www.devze.com 2022-12-18 07:19 出处:网络
This question already has answers here: Inconsistent accessibility error with the following c# code. Why?
This question already has answers here: Inconsistent accessibility error with the following c# code. Why? (3 answers) Closed 9 years ago.

I am following Rob Conery MVC Storefront tutorial series and I get an Inconsistent accessibility error from the following constructor public SqlCatalogRepository(DB dataContext) :

public class SqlCatalogRepository : ICatalogRepository
{
    DB db;

    public SqlCatalogRepository()
    {
        db = new DB();
        //turn off change tracking
        db.ObjectTrackingEnabled = false;
    }


    public SqlCatalogRepository(DB dataContext)
    {
        //override the current context
        //with the one passed in
        db = dataContext;
    }

Here 开发者_JAVA百科is the error message : Error 1 Inconsistent accessibility: parameter type 'SqlRepository.DB' is less accessible than method 'Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)'


Your DB class is not public, so you can't make a public method (or constructor) that takes it as a parameter. (What would callers outside your assembly do?)

You need to either make the DB class public or make the SqlCatalogRepository class (or its constructor) internal.

Which one you do will depend where your types are being used.
If the SqlCatalogRepository is only meant to be used inside your assembly, you should make it internal. (internal means that it's only visible to other types in the same assembly)

If it's meant to be exposed by your assembly to other assemblies, you should make the class public but the constructor internal.

If the DB class itself is meant to be used by types outside your assembly, you should make the DB class itself public.


The type DB is used in a public constructor of a public type. Therefore, the type DB must itself be public.


Check the accessor on the DB class (you dont show it here) it would need to be a Public class in oreder to allow it to be passed in to the overloaded constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消