From b23e02d90405bb4a20685a84ef7455c7f5c870c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 Aug 2025 19:20:18 +0000 Subject: [PATCH 1/3] Initial plan From 742f8b2248ea01a3494ac76e443eff204d0dd546 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 Aug 2025 19:26:36 +0000 Subject: [PATCH 2/3] Add generic type argument accessibility example to CS0050 documentation Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../compiler-messages/cs0050.md | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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(); + } +} +``` From a5020a5aa2a6382a8b5094a93fa3f2190f6365e8 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 14 Aug 2025 08:29:37 -0400 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- docs/csharp/language-reference/compiler-messages/cs0050.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/cs0050.md b/docs/csharp/language-reference/compiler-messages/cs0050.md index e741c07cb7cc9..14f3529b7044a 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0050.md +++ b/docs/csharp/language-reference/compiler-messages/cs0050.md @@ -14,7 +14,7 @@ Inconsistent accessibility: return type 'type' is less accessible than method 'm 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 +## Examples The following sample generates CS0050 because no accessibility modifier is supplied for `MyClass`, and its accessibility therefore defaults to `private`: @@ -37,8 +37,6 @@ public class MyClass2 } ``` -## Another cause - CS0050 can also occur when a generic type's type argument is less accessible than the method: ```csharp