0

When I am running this code, one is the interface other is the class. I am getting this error.

CS0051 C# Inconsistent accessibility: parameter type 'user' is less accessible than method 'cuserepository.Insert user'

This is the code for class cuserrepository:

using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
namespace signup_form
{
    public class cuserrepository : userrepository
    {
        public async Task<bool> Insert(user user)
        {
            using (IDbConnection db = new SqlConnection(Apphelper.ConnectionString))
            {
                var result = await db.ExecuteAsync(signup_form.Properties.Resources.InsertUser, new { username = user.username, fullname = user.Fullname, email = user.Email, password = user.Password });
                return result > 0;
            }
        }
    }
}

This is the code for the interface:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace signup_form
{
    interface userrepository
    {
        Task<bool> Insert(user user);
    }
}

Can anyone tell me what is the problem?

Liam
  • 27,717
  • 28
  • 128
  • 190
  • 5
    The interface method uses a type that is not public, make `user` public – Cleptus Oct 08 '20 at 08:05
  • 4
    Offtopic: Consider following coding standars, if you work in a group they will read your code a lot easier. For example: Types sould be camelcase and interfaces have an capital i prefix. Suggestion: `interface IUserRepository` and also `Insert(User user)` – Cleptus Oct 08 '20 at 08:08
  • 3
    The error has nothing to do with SQL Server or even ASP.NET. The error explains what's wrong - `user` should be public – Panagiotis Kanavos Oct 08 '20 at 08:08
  • Every time I get a compilation error like this I google the entire error text, or at least a big enough part to ensure I get good results. Typically, the docs and possible fixes appear in the first few results. – Panagiotis Kanavos Oct 08 '20 at 08:11

1 Answers1

2

The interface has no accessor on it so it will default to internal. You should make this public as outlined below.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace signup_form
{
    public interface userrepository
    {
        Task<bool> Insert(user user);
    }
}

You should also read up on Encapsulation to understand what is happening.

Also check out this answer What are the default access modifiers in C#?

Guy
  • 86
  • 9