[Solved] 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.
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
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?
4 Comments
now how did i miss this..lol..TQ!!!
ReplyDeletethank you ! sasuke
Deletei am still getting the error
ReplyDeleteomg i solved it , thankyou , internal was in other file
ReplyDelete