C # Return List - Inconsistent Availability

Possible duplicate:
Inconsistent Availability

When I try to return List<MyType> in one of my methods on something calling it from another class, it gives me the following error:

Inconsistent availability: the return type System.Collections.Generic.List<MyType> less accessible than the MyMethod(string, string, string, string, string, string, string, string, string, string, string) method MyMethod(string, string, string, string, string, string, string, string, string, string, string)

Any ideas on what to do here?

+6
source share
2 answers

Well, almost as they say. You probably have a List<SomeInternalClass> and you are returning this List<SomeInternalClass> from the PUBLIC method. So, the compiler tells you that although people can see this method, they CANNOT see the type you are trying to return. You will need to make your method or your type both internal and public.

Example:

 internal class Foo { } public class Class1 { public List<Foo> Bar() { } } 
+14
source

This usually happens when your method returns a general MyType list, which is less accessible than the method that returns it, for example

 public class TestClass { public List<MyClass> MyMethod() { return new List<MyClass>(); } private class MyClass { public string Name {get;set;} } } 
+5
source

Source: https://habr.com/ru/post/924986/


All Articles