[Solved] Inconsistent Accessibility: Parameter type is less accessible than method


Inconsistent Accessibility: Parameter type is less accessible than method


Before you get into this article, I just wanna share with you the insights of problem and direction to a working solution here.  

Introduction

If you are a developer, you may have encountered a lot of errors during application development. It happens sometimes a minor warning in code may take your entire day. 

It is obvious to google to find - that may not help as could.

The hint is try to read error message twice as possible.

Let's read again

"Inconsistent Accessibility" states an access related problem when you issue a parameter type. 

With this hint - let's get in to detail 

What Caused Error?

What could share here is the live error faced and solution that helped to save my time.

What tools I used for my development?

Visual Studio 2017  .NET Core 2.1 , C#, Web API 2 project 

The above error may occur in any sort of implementation you do in code. For here I used Interface implementation to reproduce error. 

If you are C# programmer you may know usage of Interface. 

Let's get in,

In Web API project created an interface for Logging service as ILoggingService has method declaration.

ILoggerService


What is next?

Implement the interface in a class, 

As image shown below implementing interface in three steps

STEP 1. Declare read-only interface in a class

STEP 2. Dependency Injection (DI)  in class constructor of that interface

STEP 3. Assign Interface in local declared instance


Interface Implementation


If you have noticed above image CorpPassAuthService class compiler marked in red color. 

Yes - the actual error prompted spot.

What error says is how you used interface in class is correct. But there is inaccessible privilege in interface used in parameter.

What does the compiler say?


Error is Inconsistent Accessibility: Parameter type is less accessible than method

Compiler Error
 

The Solution

This is simple solution than you may think complicated. 

As you noticed in previous section Interface class has not defined its modifier thus considered as private any class using this interface will not be accessed.

After adding public access modifier to interface inherited class has not prompted any error as below image.


Solved Inconsistent Accessibility



Summary

To conclude this article has captured error in detailed steps with descriptive images.

Even you may have skipped reading it but can get the solution just looking at images. 

In this article I have added an interface class and inherited in class that implements Dependency Injection. To avoid these errors later in your application development getting to know access modifier would help much.

The Intention of this article is to help you and save your time fixing the problem.