C# Error CS0703 – Inconsistent accessibility: constraint type ‘{1}’ is less accessible than ‘{0}’

C# Error

CS0703 – Inconsistent accessibility: constraint type ‘{1}’ is less accessible than ‘{0}’

Reason for the Error & Solution

Inconsistent accessibility: constraint type ‘identifier’ is less accessible than ‘identifier’

A constraint may not force the generic parameter to be less accessible than the generic class itself. In the following example, while the generic class C<T> is declared public, the constraint attempts to force T to implement an internal interface. Even if this were allowed, only clients with internal access would be able to create the parameter for the class, so in effect, the class could be used only by clients with internal access.

To get rid of this error, make sure the access level of the generic class is not less restrictive than any classes or interfaces that appear in the bounds.

The following sample generates CS0703:

// CS0703.cs  
internal interface I {}  
public class C<T> where T : I  // CS0703 – I is internal; C<T> is public  
{  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...