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 is the error message :
Error 1 Inconsistent accessibility: parameter type ‘SqlRepository.DB’ is less accessible than method ‘Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)’
Your
DBclass is not public, so you can’t make apublicmethod (or constructor) that takes it as a parameter. (What would callers outside your assembly do?)You need to either make the
DBclasspublicor make theSqlCatalogRepositoryclass (or its constructor)internal.Which one you do will depend where your types are being used.
If the
SqlCatalogRepositoryis only meant to be used inside your assembly, you should make itinternal. (internalmeans 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
publicbut the constructorinternal.If the
DBclass itself is meant to be used by types outside your assembly, you should make theDBclass itselfpublic.