Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion docs/csharp/language-reference/compiler-messages/cs0050.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<CeisData> BuildCeis() // CS0050
{
return new ObservableCollection<CeisData>();
}
}
```

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<CeisData> BuildCeis() // OK
{
return new ObservableCollection<CeisData>();
}
}
```
Loading