diff --git a/docs/csharp/language-reference/compiler-messages/cs0050.md b/docs/csharp/language-reference/compiler-messages/cs0050.md index fd8f0454de233..e741c07cb7cc9 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0050.md +++ b/docs/csharp/language-reference/compiler-messages/cs0050.md @@ -12,7 +12,7 @@ ms.assetid: dead2d28-f4db-4afe-b8dd-38968625f7c3 Inconsistent accessibility: return type 'type' is less accessible than method 'method' - The return type and each of the types referenced in the formal parameter list of a method must be at least as accessible as the method itself. For more information, see [Access Modifiers](../../programming-guide/classes-and-structs/access-modifiers.md). + The return type and each of the types referenced in the formal parameter list of a method must be at least as accessible as the method itself. This includes type arguments of generic types used in the return type or parameters. For more information, see [Access Modifiers](../../programming-guide/classes-and-structs/access-modifiers.md). ## Example @@ -36,3 +36,45 @@ public class MyClass2 public static void Main() { } } ``` + +## Another cause + +CS0050 can also occur when a generic type's type argument is less accessible than the method: + +```csharp +// CS0050_Generic.cs +using System.Collections.ObjectModel; + +internal class CeisData // Internal class +{ + public string Name { get; set; } +} + +public class MyClass +{ + public static ObservableCollection BuildCeis() // CS0050 + { + return new ObservableCollection(); + } +} +``` + +To fix this error, make the type argument at least as accessible as the method: + +```csharp +// Fixed version +using System.Collections.ObjectModel; + +public class CeisData // Now public +{ + public string Name { get; set; } +} + +public class MyClass +{ + public static ObservableCollection BuildCeis() // OK + { + return new ObservableCollection(); + } +} +```