From 4c4fe19292d803e10d1ea24844f34a6d464fae0a Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 27 Apr 2026 15:28:14 -0400 Subject: [PATCH 1/6] Create stub file Create the stub file for the new function pointer errors and warnings. --- .../delegate-function-pointer-diagnostics.md | 65 +++++++++++++++++++ docs/csharp/language-reference/toc.yml | 5 ++ ...n-t-have-specifics-on-this-csharp-error.md | 16 ----- 3 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md new file mode 100644 index 0000000000000..c0c57b4c05a1a --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -0,0 +1,65 @@ +--- +title: "Resolve errors and warnings related to delegate and function pointer declarations and uses" +description: "This article helps you diagnose and correct compiler errors and warnings related to delegate and function pointer declarations and uses" +f1_keywords: + - "CS8755" + - "CS8756" + - "CS8757" + - "CS8758" + - "CS8759" + - "CS8786" + - "CS8787" + - "CS8788" + - "CS8789" + - "CS8806" + - "CS8807" + - "CS8808" + - "CS8809" + - "CS8811" + - "CS8909" + - "CS8911" +helpviewer_keywords: + - "CS8755" + - "CS8756" + - "CS8757" + - "CS8758" + - "CS8759" + - "CS8786" + - "CS8787" + - "CS8788" + - "CS8789" + - "CS8806" + - "CS8807" + - "CS8808" + - "CS8809" + - "CS8811" + - "CS8909" + - "CS8911" +ms.date: 04/27/2026 +ai-usage: ai-assisted +--- + +# Resolve errors and warnings for delegate and function pointer declarations + +This article covers the following compiler errors and warnings: + + + +- [**CS8755**](#anchor-tbd): *'modifier' cannot be used as a modifier on a function pointer parameter.* +- [**CS8756**](#anchor-tbd): *Function pointer 'type' does not take 'count' arguments.* +- [**CS8757**](#anchor-tbd): *No overload for 'method' matches function pointer 'type'.* +- [**CS8758**](#anchor-tbd): *Ref mismatch between 'method' and function pointer 'type'.* +- [**CS8759**](#anchor-tbd): *Cannot create a function pointer for 'method' because it is not a static method.* +- [**CS8786**](#anchor-tbd): *Calling convention of 'convention' is not compatible with 'convention'.* +- [**CS8787**](#anchor-tbd): *Cannot convert method group to function pointer. (Are you missing a '&'?)* +- [**CS8788**](#anchor-tbd): *Cannot use an extension method with a receiver as the target of a '&' operator.* +- [**CS8789**](#anchor-tbd): *The type of a local declared in a fixed statement cannot be a function pointer type.* +- [**CS8806**](#anchor-tbd): *The calling convention of 'convention' is not supported by the language.* +- [**CS8807**](#anchor-tbd): *'specifier' is not a valid calling convention specifier for a function pointer.* +- [**CS8808**](#anchor-tbd): *'modifier' is not a valid function pointer return type modifier. Valid modifiers are 'ref' and 'ref readonly'.* +- [**CS8809**](#anchor-tbd): *A return type can only have one 'modifier' modifier.* +- [**CS8811**](#anchor-tbd): *Cannot convert &method group 'method' to delegate type 'type'.* +- [**CS8909**](#anchor-tbd): *Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.* +- [**CS8911**](#anchor-tbd): *Using a function pointer type in this context is not supported.* diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index 91525b32de914..5b47c6a8021ce 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -663,6 +663,11 @@ items: CS1706, CS1731, CS1732, CS1764, CS1911, CS1989, CS3006, CS8030, CS8175, CS8820, CS8821, CS8916, CS8917, CS8934, CS8971, CS8972, CS8974, CS8975, CS9098, CS9099, CS9100, CS9236 + - name: Delegate and function pointer declarations + href: ./compiler-messages/delegate-function-pointer-diagnostics.md + displayName: > + CS8755, CS8756, CS8757, CS8758, CS8759, CS8786, CS8787, CS8788, CS8789, + CS8806, CS8807, CS8808, CS8809, CS8811, CS8909, CS8911 - name: Overload resolution href: ./compiler-messages/overload-resolution.md displayName: > diff --git a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md index 73f06dd87addc..92555a1979bec 100644 --- a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md +++ b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md @@ -290,11 +290,6 @@ f1_keywords: - "CS8752" # target type new - "CS8753" - "CS8754" - - "CS8755" # function pointer - - "CS8756" - - "CS8757" - - "CS8758" - - "CS8759" - "CS8760" # misc - "CS8761" - "CS8771" @@ -302,15 +297,6 @@ f1_keywords: - "CS8783" # local function - "CS8784" # source generator - "CS8785" - - "CS8786" # function pointers - - "CS8787" - - "CS8788" - - "CS8789" - - "CS8806" - - "CS8807" - - "CS8808" - - "CS8809" - - "CS8811" - "CS8813" # module initializers - "CS8814" - "CS8815" @@ -340,8 +326,6 @@ f1_keywords: - "CS8902" - "CS8903" # init only property - "CS8906" # record - - "CS8909" # function pointer - - "CS8911" # function pointer # Coming in C# 15 - "CS9343" # misc - "CS9346" From 7d410574a713ca3630ac3f134523dab3acb9bf20 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 27 Apr 2026 16:26:28 -0400 Subject: [PATCH 2/6] Consolidate additional articles Search additional articles and consolidate additional articles., --- .openpublishing.redirection.csharp.json | 28 +++ .../delegate-function-pointer-diagnostics.md | 184 ++++++++++++++++++ docs/csharp/language-reference/toc.yml | 19 +- docs/csharp/misc/cs0059.md | 37 ---- docs/csharp/misc/cs0123.md | 36 ---- docs/csharp/misc/cs0148.md | 17 -- docs/csharp/misc/cs0410.md | 38 ---- docs/csharp/misc/cs0644.md | 34 ---- docs/csharp/misc/cs1599.md | 39 ---- docs/csharp/misc/cs1958.md | 38 ---- 10 files changed, 215 insertions(+), 255 deletions(-) delete mode 100644 docs/csharp/misc/cs0059.md delete mode 100644 docs/csharp/misc/cs0123.md delete mode 100644 docs/csharp/misc/cs0148.md delete mode 100644 docs/csharp/misc/cs0410.md delete mode 100644 docs/csharp/misc/cs0644.md delete mode 100644 docs/csharp/misc/cs1599.md delete mode 100644 docs/csharp/misc/cs1958.md diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 52f0ca6592ae6..c280661618637 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -20,6 +20,18 @@ "source_path_from_root": "/docs/csharp/misc/cs0031.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0059.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0123.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0148.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, { "source_path_from_root": "/docs/csharp/misc/cs0220.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" @@ -28,6 +40,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0221.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0410.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, { "source_path_from_root": "/docs/csharp/misc/cs0463.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" @@ -40,6 +56,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0594.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0644.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, { "source_path_from_root": "/docs/csharp/misc/cs0652.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/overloaded-operator-errors" @@ -204,6 +224,14 @@ "source_path_from_root": "/docs/csharp/misc/cs1559.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/entry-point-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs1599.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs1958.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics" + }, { "source_path_from_root": "/docs/csharp/misc/cs2017.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/entry-point-errors" diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md index c0c57b4c05a1a..fdc88bbfe2aef 100644 --- a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -2,6 +2,13 @@ title: "Resolve errors and warnings related to delegate and function pointer declarations and uses" description: "This article helps you diagnose and correct compiler errors and warnings related to delegate and function pointer declarations and uses" f1_keywords: + - "CS0059" + - "CS0123" + - "CS0148" + - "CS0410" + - "CS0644" + - "CS1599" + - "CS1958" - "CS8755" - "CS8756" - "CS8757" @@ -19,6 +26,13 @@ f1_keywords: - "CS8909" - "CS8911" helpviewer_keywords: + - "CS0059" + - "CS0123" + - "CS0148" + - "CS0410" + - "CS0644" + - "CS1599" + - "CS1958" - "CS8755" - "CS8756" - "CS8757" @@ -47,6 +61,13 @@ This article covers the following compiler errors and warnings: That's by design. The text closely matches the text of the compiler error / warning for SEO purposes. --> +- [**CS0059**](#anchor-tbd): *Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate'.* +- [**CS0123**](#anchor-tbd): *No overload for 'method' matches delegate 'delegate'.* +- [**CS0148**](#anchor-tbd): *The delegate 'delegate' does not have a valid constructor.* +- [**CS0410**](#anchor-tbd): *No overload for 'method' has the correct parameter and return types.* +- [**CS0644**](#anchor-tbd): *'class' cannot derive from special class 'class'.* +- [**CS1599**](#anchor-tbd): *The return type of a method, delegate, or function pointer cannot be 'type'.* +- [**CS1958**](#anchor-tbd): *Object and collection initializer expressions may not be applied to a delegate creation expression.* - [**CS8755**](#anchor-tbd): *'modifier' cannot be used as a modifier on a function pointer parameter.* - [**CS8756**](#anchor-tbd): *Function pointer 'type' does not take 'count' arguments.* - [**CS8757**](#anchor-tbd): *No overload for 'method' matches function pointer 'type'.* @@ -63,3 +84,166 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS8811**](#anchor-tbd): *Cannot convert &method group 'method' to delegate type 'type'.* - [**CS8909**](#anchor-tbd): *Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.* - [**CS8911**](#anchor-tbd): *Using a function pointer type in this context is not supported.* + +## CS0059 + +Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate' + +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 following sample generates CS0059: + +```csharp +// CS0059.cs +class MyClass //defaults to private accessibility +// try the following line instead +// public class MyClass +{ +} + +public delegate void MyClassDel( MyClass myClass); // CS0059 + +public class Program +{ + public static void Main() + { + } +} +``` + +## CS0123 + +No overload for 'method' matches delegate 'delegate' + +An attempt to create a delegate failed because the correct signature was not used. Instances of a delegate must be declared with the same signature as the delegate declaration. + +You can resolve this error by adjusting either the method or delegate signature. For more information, see [Delegates](../../programming-guide/delegates/index.md). + +The following sample generates CS0123. + +```csharp +// CS0123.cs +delegate void D(); +delegate void D2(int i); + +public class C +{ + public static void f(int i) {} + + public static void Main() + { + D d = new D(f); // CS0123 + D2 d2 = new D2(f); // OK + } +} +``` + +## CS0148 + +The delegate 'delegate' does not have a valid constructor + +You imported and used a managed program (one that uses the .NET runtime) that was created with another compiler. That compiler allowed an ill-formed [delegate](../../language-reference/builtin-types/reference-types.md) constructor. For more information, see [Delegates](../../programming-guide/delegates/index.md). + +[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)] + +## CS0410 + +No overload for 'method' has the correct parameter and return types + +This error occurs if you try to instantiate a delegate with a function that has the wrong parameter types. The parameter types of the delegate must match the function that you are assigning to the delegate. + +The following example generates CS0410: + +```csharp +// CS0410.cs +// compile with: /langversion:ISO-1 + +class Test +{ + delegate void D(double d ); + static void F(int i) { } + + static void Main() + { + D d = new D(F); // CS0410 + } +} +``` + +> [!NOTE] +> This compiler error is no longer used in Roslyn. The previous example generates CS0123 when compiled with Roslyn. + +## CS0644 + +'class' cannot derive from special class 'class' + +Classes can't explicitly inherit from any of the following base classes: + +- **System.Enum** +- **System.ValueType** +- **System.Delegate** +- **System.Array** + +These are used as implicit base classes by the compiler. For example, **System.ValueType** is the implicit base class of structs. + +The following sample generates CS0644: + +```csharp +// CS0644.cs +class MyClass : System.ValueType // CS0644 +{ +} +``` + +## CS1599 + +The return type of a method, delegate, or function pointer cannot be 'type' + +Some types in the .NET class library, for example, , and can't be used as return types because they can potentially be used to perform unsafe operations. + +The following sample generates CS1599: + +```csharp +// CS1599.cs +using System; + +class MyClass +{ + public static void Main() + { + } + + public TypedReference Test1() // CS1599 + { + return null; + } + + public ArgIterator Test2() // CS1599 + { + return null; + } +} +``` + +## CS1958 + +Object and collection initializer expressions may not be applied to a delegate creation expression + +A delegate has no members like a class or struct has, and so there's nothing for an object initializer to initialize. If you encounter this error, it's probably because there are braces after the delegate creation expression. Remove the braces and this error disappears. + +The following code produces CS1958: + +```csharp +// cs1958.cs +public class MemberInitializerTest +{ + delegate void D(); + public static void GenericMethod() { } + public static void Run() + { + D genD = new D(GenericMethod) { }; // CS1958 + // Try the following line instead + // D genD = new D(GenericMethod); + } +} +``` diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index 5b47c6a8021ce..3085422541a1d 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -666,8 +666,9 @@ items: - name: Delegate and function pointer declarations href: ./compiler-messages/delegate-function-pointer-diagnostics.md displayName: > - CS8755, CS8756, CS8757, CS8758, CS8759, CS8786, CS8787, CS8788, CS8789, - CS8806, CS8807, CS8808, CS8809, CS8811, CS8909, CS8911 + CS0059, CS0123, CS0148, CS0410, CS0644, CS1599, CS1958, CS8755, CS8756, CS8757, + CS8758, CS8759, CS8786, CS8787, CS8788, CS8789, CS8806, CS8807, CS8808, CS8809, + CS8811, CS8909, CS8911 - name: Overload resolution href: ./compiler-messages/overload-resolution.md displayName: > @@ -811,8 +812,6 @@ items: href: ../misc/cs0055.md - name: CS0058 href: ../misc/cs0058.md - - name: CS0059 - href: ../misc/cs0059.md - name: CS0060 href: ../misc/cs0060.md - name: CS0061 @@ -871,8 +870,6 @@ items: href: ./compiler-messages/cs0120.md - name: CS0122 href: ./compiler-messages/cs0122.md - - name: CS0123 - href: ../misc/cs0123.md - name: CS0126 href: ../misc/cs0126.md - name: CS0127 @@ -901,8 +898,6 @@ items: href: ../misc/cs0145.md - name: CS0146 href: ../misc/cs0146.md - - name: CS0148 - href: ../misc/cs0148.md - name: CS0149 href: ../misc/cs0149.md - name: CS0150 @@ -1021,8 +1016,6 @@ items: href: ../misc/cs0406.md - name: CS0409 href: ../misc/cs0409.md - - name: CS0410 - href: ../misc/cs0410.md - name: CS0411 href: ../misc/cs0411.md - name: CS0418 @@ -1163,8 +1156,6 @@ items: href: ../misc/cs0622.md - name: CS0635 href: ../misc/cs0635.md - - name: CS0644 - href: ../misc/cs0644.md - name: CS0645 href: ../misc/cs0645.md - name: CS0648 @@ -1433,8 +1424,6 @@ items: href: ../misc/cs1594.md - name: CS1597 href: ../misc/cs1597.md - - name: CS1599 - href: ../misc/cs1599.md - name: CS1600 href: ../misc/cs1600.md - name: CS1601 @@ -1581,8 +1570,6 @@ items: href: ../misc/cs1949.md - name: CS1955 href: ../misc/cs1955.md - - name: CS1958 - href: ../misc/cs1958.md - name: CS1959 href: ../misc/cs1959.md - name: CS2001 diff --git a/docs/csharp/misc/cs0059.md b/docs/csharp/misc/cs0059.md deleted file mode 100644 index 1a46f3ff3dff0..0000000000000 --- a/docs/csharp/misc/cs0059.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: "Compiler Error CS0059" -title: "Compiler Error CS0059" -ms.date: 07/20/2015 -f1_keywords: - - "CS0059" -helpviewer_keywords: - - "CS0059" -ms.assetid: 25a8624b-7f7b-4487-ba80-413d57f9132b ---- -# Compiler Error CS0059 - -Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate' - - 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). - -## Example - - The following sample generates CS0059: - -```csharp -// CS0059.cs -class MyClass //defaults to private accessibility -// try the following line instead -// public class MyClass -{ -} - -public delegate void MyClassDel( MyClass myClass); // CS0059 - -public class Program -{ - public static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0123.md b/docs/csharp/misc/cs0123.md deleted file mode 100644 index ab4b32d68fe83..0000000000000 --- a/docs/csharp/misc/cs0123.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -description: "Compiler Error CS0123" -title: "Compiler Error CS0123" -ms.date: 07/20/2015 -f1_keywords: - - "CS0123" -helpviewer_keywords: - - "CS0123" -ms.assetid: 57be2c58-6d87-40af-9376-cd7f91023044 ---- -# Compiler Error CS0123 - -No overload for 'method' matches delegate 'delegate' - - An attempt to create a delegate failed because the correct signature was not used. Instances of a delegate must be declared with the same signature as the delegate declaration. - - You can resolve this error by adjusting either the method or delegate signature. For more information, see [Delegates](../programming-guide/delegates/index.md). - - The following sample generates CS0123. - -```csharp -// CS0123.cs -delegate void D(); -delegate void D2(int i); - -public class C -{ - public static void f(int i) {} - - public static void Main() - { - D d = new D(f); // CS0123 - D2 d2 = new D2(f); // OK - } -} -``` diff --git a/docs/csharp/misc/cs0148.md b/docs/csharp/misc/cs0148.md deleted file mode 100644 index 3b9f2aaf355c6..0000000000000 --- a/docs/csharp/misc/cs0148.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -description: "Compiler Error CS0148" -title: "Compiler Error CS0148" -ms.date: 07/20/2015 -f1_keywords: - - "CS0148" -helpviewer_keywords: - - "CS0148" -ms.assetid: d199afbf-02e1-4a1c-9e36-07bf86f1a2fb ---- -# Compiler Error CS0148 - -The delegate 'delegate' does not have a valid constructor - -You imported and used a managed program (one that uses the .NET runtime) that was created with another compiler. That compiler allowed an ill-formed [delegate](../language-reference/builtin-types/reference-types.md) constructor. For more information, see [Delegates](../programming-guide/delegates/index.md). - -[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)] diff --git a/docs/csharp/misc/cs0410.md b/docs/csharp/misc/cs0410.md deleted file mode 100644 index 1cf584f9050fb..0000000000000 --- a/docs/csharp/misc/cs0410.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -description: "Compiler Error CS0410" -title: "Compiler Error CS0410" -ms.date: 07/20/2015 -f1_keywords: - - "CS0410" -helpviewer_keywords: - - "CS0410" -ms.assetid: a8b11042-9119-465e-abf6-235cbc7b8db5 ---- -# Compiler Error CS0410 - -No overload for 'method' has the correct parameter and return types - - This error occurs if you try to instantiate a delegate with a function that has the wrong parameter types. The parameter types of the delegate must match the function that you are assigning to the delegate. - -## Example - - The following example generates CS0410: - -```csharp -// CS0410.cs -// compile with: /langversion:ISO-1 - -class Test -{ - delegate void D(double d ); - static void F(int i) { } - - static void Main() - { - D d = new D(F); // CS0410 - } -} -``` - -> [!NOTE] -> This compiler error is no longer used in Roslyn. The previous example generates CS0123 when compiled with Roslyn. diff --git a/docs/csharp/misc/cs0644.md b/docs/csharp/misc/cs0644.md deleted file mode 100644 index 86a42c7b19d8b..0000000000000 --- a/docs/csharp/misc/cs0644.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -description: "Compiler Error CS0644" -title: "Compiler Error CS0644" -ms.date: 07/20/2015 -f1_keywords: - - "CS0644" -helpviewer_keywords: - - "CS0644" -ms.assetid: 835f3ee2-f897-4ba2-ad13-af629a9ab7fe ---- -# Compiler Error CS0644 - -'class1' cannot derive from special class 'class2' - - Classes cannot explicitly inherit from any of the following base classes: - -- **System.Enum** - -- **System.ValueType** - -- **System.Delegate** - -- **System.Array** - - These are used as implicit base classes by the compiler. For example, **System.ValueType** is the implicit base class of structs. - - The following sample generates CS0644: - -```csharp -// CS0644.cs -class MyClass : System.ValueType // CS0644 -{ -} -``` diff --git a/docs/csharp/misc/cs1599.md b/docs/csharp/misc/cs1599.md deleted file mode 100644 index 0c467f3868c8c..0000000000000 --- a/docs/csharp/misc/cs1599.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -description: "Compiler Error CS1599" -title: "Compiler Error CS1599" -ms.date: 07/20/2015 -f1_keywords: - - "CS1599" -helpviewer_keywords: - - "CS1599" -ms.assetid: 4cdb282d-0f5d-459b-afc1-8980fbb22067 ---- -# Compiler Error CS1599 - -Method or delegate cannot return type 'type' - - Some types in the .NET class library, for example, , and cannot be used as return types because they can potentially be used to perform unsafe operations. - - The following sample generates CS1599: - -```csharp -// CS1599.cs -using System; - -class MyClass -{ - public static void Main() - { - } - - public TypedReference Test1() // CS1599 - { - return null; - } - - public ArgIterator Test2() // CS1599 - { - return null; - } -} -``` diff --git a/docs/csharp/misc/cs1958.md b/docs/csharp/misc/cs1958.md deleted file mode 100644 index 0425a8076bb68..0000000000000 --- a/docs/csharp/misc/cs1958.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -description: "Learn more about: Compiler Error CS1958" -title: "Compiler Error CS1958" -ms.date: 07/20/2015 -f1_keywords: - - "CS1958" -helpviewer_keywords: - - "CS1958" -ms.assetid: bb6f3bb2-ea93-4d2e-984c-da9c99f5653f ---- -# Compiler Error CS1958 - -Object and collection initializer expressions may not be applied to a delegate creation expression. - - A delegate has no members like a class or struct has, and so there is nothing for an object initializer to initialize. If you encounter this error, it is probably because there are braces after the delegate creation expression. Just remove the braces and this error will disappear. - -## To correct this error - -1. Remove the braces. - -## Example - - The following code produces CS1958: - -```csharp -// cs1958.cs -public class MemberInitializerTest -{ - delegate void D(); - public static void GenericMethod() { } - public static void Run() - { - D genD = new D(GenericMethod) { }; // CS1958 - // Try the following line instead - // D genD = new D(GenericMethod); - } -} -``` From b5494221cbc90b2b3d2345c599e22fa5cbc7c758 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 28 Apr 2026 14:06:58 -0400 Subject: [PATCH 3/6] Content edit --- .../delegate-function-pointer-diagnostics.md | 251 ++++++------------ 1 file changed, 85 insertions(+), 166 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md index fdc88bbfe2aef..af5b1fe715f9b 100644 --- a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -61,189 +61,108 @@ This article covers the following compiler errors and warnings: That's by design. The text closely matches the text of the compiler error / warning for SEO purposes. --> -- [**CS0059**](#anchor-tbd): *Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate'.* -- [**CS0123**](#anchor-tbd): *No overload for 'method' matches delegate 'delegate'.* -- [**CS0148**](#anchor-tbd): *The delegate 'delegate' does not have a valid constructor.* -- [**CS0410**](#anchor-tbd): *No overload for 'method' has the correct parameter and return types.* -- [**CS0644**](#anchor-tbd): *'class' cannot derive from special class 'class'.* -- [**CS1599**](#anchor-tbd): *The return type of a method, delegate, or function pointer cannot be 'type'.* -- [**CS1958**](#anchor-tbd): *Object and collection initializer expressions may not be applied to a delegate creation expression.* -- [**CS8755**](#anchor-tbd): *'modifier' cannot be used as a modifier on a function pointer parameter.* -- [**CS8756**](#anchor-tbd): *Function pointer 'type' does not take 'count' arguments.* -- [**CS8757**](#anchor-tbd): *No overload for 'method' matches function pointer 'type'.* -- [**CS8758**](#anchor-tbd): *Ref mismatch between 'method' and function pointer 'type'.* -- [**CS8759**](#anchor-tbd): *Cannot create a function pointer for 'method' because it is not a static method.* -- [**CS8786**](#anchor-tbd): *Calling convention of 'convention' is not compatible with 'convention'.* -- [**CS8787**](#anchor-tbd): *Cannot convert method group to function pointer. (Are you missing a '&'?)* -- [**CS8788**](#anchor-tbd): *Cannot use an extension method with a receiver as the target of a '&' operator.* -- [**CS8789**](#anchor-tbd): *The type of a local declared in a fixed statement cannot be a function pointer type.* -- [**CS8806**](#anchor-tbd): *The calling convention of 'convention' is not supported by the language.* -- [**CS8807**](#anchor-tbd): *'specifier' is not a valid calling convention specifier for a function pointer.* -- [**CS8808**](#anchor-tbd): *'modifier' is not a valid function pointer return type modifier. Valid modifiers are 'ref' and 'ref readonly'.* -- [**CS8809**](#anchor-tbd): *A return type can only have one 'modifier' modifier.* -- [**CS8811**](#anchor-tbd): *Cannot convert &method group 'method' to delegate type 'type'.* -- [**CS8909**](#anchor-tbd): *Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.* -- [**CS8911**](#anchor-tbd): *Using a function pointer type in this context is not supported.* - -## CS0059 - -Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate' - -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 following sample generates CS0059: - -```csharp -// CS0059.cs -class MyClass //defaults to private accessibility -// try the following line instead -// public class MyClass -{ -} - -public delegate void MyClassDel( MyClass myClass); // CS0059 - -public class Program -{ - public static void Main() - { - } -} -``` - -## CS0123 - -No overload for 'method' matches delegate 'delegate' - -An attempt to create a delegate failed because the correct signature was not used. Instances of a delegate must be declared with the same signature as the delegate declaration. - -You can resolve this error by adjusting either the method or delegate signature. For more information, see [Delegates](../../programming-guide/delegates/index.md). - -The following sample generates CS0123. - -```csharp -// CS0123.cs -delegate void D(); -delegate void D2(int i); - -public class C -{ - public static void f(int i) {} - - public static void Main() - { - D d = new D(f); // CS0123 - D2 d2 = new D2(f); // OK - } -} -``` - -## CS0148 - -The delegate 'delegate' does not have a valid constructor - -You imported and used a managed program (one that uses the .NET runtime) that was created with another compiler. That compiler allowed an ill-formed [delegate](../../language-reference/builtin-types/reference-types.md) constructor. For more information, see [Delegates](../../programming-guide/delegates/index.md). - -[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)] - -## CS0410 - -No overload for 'method' has the correct parameter and return types - -This error occurs if you try to instantiate a delegate with a function that has the wrong parameter types. The parameter types of the delegate must match the function that you are assigning to the delegate. - -The following example generates CS0410: - -```csharp -// CS0410.cs -// compile with: /langversion:ISO-1 - -class Test -{ - delegate void D(double d ); - static void F(int i) { } - - static void Main() - { - D d = new D(F); // CS0410 - } -} -``` +- [**CS0059**](#delegate-signature-mismatches): *Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate'.* +- [**CS0123**](#delegate-signature-mismatches): *No overload for 'method' matches delegate 'delegate'.* +- [**CS0148**](#delegate-signature-mismatches): *The delegate 'delegate' does not have a valid constructor.* +- [**CS0410**](#delegate-signature-mismatches): *No overload for 'method' has the correct parameter and return types.* +- [**CS0644**](#delegate-type-restrictions): *'class' cannot derive from special class 'class'.* +- [**CS1599**](#delegate-type-restrictions): *The return type of a method, delegate, or function pointer cannot be 'type'.* +- [**CS1958**](#delegate-type-restrictions): *Object and collection initializer expressions may not be applied to a delegate creation expression.* +- [**CS8755**](#function-pointer-signature-mismatches): *'modifier' cannot be used as a modifier on a function pointer parameter.* +- [**CS8756**](#function-pointer-signature-mismatches): *Function pointer 'type' does not take 'count' arguments.* +- [**CS8757**](#function-pointer-signature-mismatches): *No overload for 'method' matches function pointer 'type'.* +- [**CS8758**](#function-pointer-signature-mismatches): *Ref mismatch between 'method' and function pointer 'type'.* +- [**CS8759**](#function-pointer-signature-mismatches): *Cannot create a function pointer for 'method' because it is not a static method.* +- [**CS8786**](#function-pointer-calling-conventions-and-return-types): *Calling convention of 'convention' is not compatible with 'convention'.* +- [**CS8787**](#function-pointer-signature-mismatches): *Cannot convert method group to function pointer. (Are you missing a '&'?)* +- [**CS8788**](#function-pointer-signature-mismatches): *Cannot use an extension method with a receiver as the target of a '&' operator.* +- [**CS8789**](#function-pointer-usage-restrictions): *The type of a local declared in a fixed statement cannot be a function pointer type.* +- [**CS8806**](#function-pointer-calling-conventions-and-return-types): *The calling convention of 'convention' is not supported by the language.* +- [**CS8807**](#function-pointer-calling-conventions-and-return-types): *'specifier' is not a valid calling convention specifier for a function pointer.* +- [**CS8808**](#function-pointer-calling-conventions-and-return-types): *'modifier' is not a valid function pointer return type modifier. Valid modifiers are 'ref' and 'ref readonly'.* +- [**CS8809**](#function-pointer-calling-conventions-and-return-types): *A return type can only have one 'modifier' modifier.* +- [**CS8811**](#function-pointer-signature-mismatches): *Cannot convert &method group 'method' to delegate type 'type'.* +- [**CS8909**](#function-pointer-usage-restrictions): *Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.* +- [**CS8911**](#function-pointer-usage-restrictions): *Using a function pointer type in this context is not supported.* + +## Delegate signature mismatches + +- **CS0059**: *Inconsistent accessibility: parameter type 'type' is less accessible than delegate 'delegate'.* +- **CS0123**: *No overload for 'method' matches delegate 'delegate'.* +- **CS0148**: *The delegate 'delegate' does not have a valid constructor.* +- **CS0410**: *No overload for 'method' has the correct parameter and return types.* + +When you create or assign a delegate, the compiler verifies that the target method's signature matches the delegate type's declaration. The signature includes the parameter types, return type, and accessibility. For the full rules, see [Delegates](../../programming-guide/delegates/index.md) and [Accessibility constraints](~/_csharpstandard/standard/basic-concepts.md#755-accessibility-constraints) in the C# specification. + +- Change all parameter types in the delegate declaration to types that are at least as accessible as the delegate itself (**CS0059**). A `public` delegate can't reference a less-accessible type in its parameter list because callers outside the assembly wouldn't be able to provide the argument. For more information, see [Access Modifiers](../../programming-guide/classes-and-structs/access-modifiers.md). +- Adjust either the method signature or the delegate signature so the parameter types and return type match exactly (**CS0123**). The compiler requires an exact signature match when you assign a method to a delegate. +- Verify that the delegate was compiled by a conformant compiler (**CS0148**). This error occurs when you import a managed assembly built by a compiler that produced an ill-formed delegate constructor. Recompile the assembly with a standards-compliant compiler to resolve the error. > [!NOTE] -> This compiler error is no longer used in Roslyn. The previous example generates CS0123 when compiled with Roslyn. +> **CS0410** is no longer produced by the current C# compiler. The same condition now produces CS0123 instead. Older assemblies compiled with earlier compilers might still reference this error code. -## CS0644 +**CS0148** is a build-only diagnostic: -'class' cannot derive from special class 'class' - -Classes can't explicitly inherit from any of the following base classes: - -- **System.Enum** -- **System.ValueType** -- **System.Delegate** -- **System.Array** +[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)] -These are used as implicit base classes by the compiler. For example, **System.ValueType** is the implicit base class of structs. +## Delegate type restrictions -The following sample generates CS0644: +- **CS0644**: *'class' cannot derive from special class 'class'.* +- **CS1599**: *The return type of a method, delegate, or function pointer cannot be 'type'.* +- **CS1958**: *Object and collection initializer expressions may not be applied to a delegate creation expression.* -```csharp -// CS0644.cs -class MyClass : System.ValueType // CS0644 -{ -} -``` +The C# language restricts how you can use certain special types, including `System.Delegate`. For the full rules on delegate declarations, see [Delegates](../../programming-guide/delegates/index.md) and [Delegates](~/_csharpstandard/standard/delegates.md) in the C# specification. -## CS1599 +- Remove the explicit base class and use a `delegate` declaration instead (**CS0644**). Classes can't explicitly inherit from `System.Delegate`, `System.Enum`, `System.ValueType`, or `System.Array`. The compiler uses these types as implicit base classes. For example, every `delegate` declaration implicitly derives from `System.Delegate`. +- Change the return type to a type that's permitted as a return value (**CS1599**). Certain types in the .NET class library, such as , , and , can't be used as return types for methods, delegates, or function pointers because they can potentially enable unsafe stack operations. +- Remove the braces after the delegate creation expression (**CS1958**). Delegates don't have members that you can set through object or collection initializer syntax. If you have `{ }` after a `new DelegateType(method)` expression, remove the braces. -The return type of a method, delegate, or function pointer cannot be 'type' +## Function pointer signature mismatches -Some types in the .NET class library, for example, , and can't be used as return types because they can potentially be used to perform unsafe operations. +- **CS8755**: *'modifier' cannot be used as a modifier on a function pointer parameter.* +- **CS8756**: *Function pointer 'type' does not take 'count' arguments.* +- **CS8757**: *No overload for 'method' matches function pointer 'type'.* +- **CS8758**: *Ref mismatch between 'method' and function pointer 'type'.* +- **CS8759**: *Cannot create a function pointer for 'method' because it is not a static method.* +- **CS8787**: *Cannot convert method group to function pointer. (Are you missing a '&'?)* +- **CS8788**: *Cannot use an extension method with a receiver as the target of a '&' operator.* +- **CS8811**: *Cannot convert &method group 'method' to delegate type 'type'.* -The following sample generates CS1599: +When you assign a method to a function pointer by using the address-of (`&`) operator, the compiler checks that the method's signature matches the function pointer type. For the full rules on function pointer declarations and usage, see [Function pointers](../unsafe-code.md#function-pointers) and [Unsafe code](../unsafe-code.md). -```csharp -// CS1599.cs -using System; +- Remove the unsupported modifier from the function pointer parameter (**CS8755**). Function pointer parameters support only `ref`, `out`, and `in` modifiers. Other parameter modifiers, such as `params`, aren't valid in function pointer type declarations. +- Change the number of arguments at the call site to match the function pointer's parameter count (**CS8756**). The function pointer type defines a fixed number of parameters, and you must pass exactly that many arguments. +- Adjust the method's signature so its parameter types, return type, and parameter count match the function pointer type (**CS8757**). Unlike delegates, function pointers don't support implicit conversions between compatible method signatures. The match must be exact. +- Align the `ref`, `out`, or `in` modifiers between the method's parameters and the function pointer type's parameters (**CS8758**). Each parameter's ref kind must match exactly. A `ref` parameter can't satisfy an `in` or `out` position in the function pointer type. +- Change the target method to `static` (**CS8759**). Function pointers can only point to static methods because they represent raw function addresses without an associated object instance. +- Add the `&` operator before the method group when assigning to a function pointer (**CS8787**). Unlike delegates, function pointers require the explicit address-of operator: `delegate* ptr = &MyMethod;`. +- Use a static method instead of an extension method with a receiver (**CS8788**). The `&` operator requires a direct method reference. Extension methods called on an instance have an implicit receiver that can't be captured in a function pointer. +- Remove the `&` operator and use delegate syntax instead, or change the target type from a delegate to a function pointer (**CS8811**). The `&` operator produces a function pointer, not a delegate. To assign a method group to a delegate type, omit the `&` and use standard delegate creation syntax. -class MyClass -{ - public static void Main() - { - } +## Function pointer calling conventions and return types - public TypedReference Test1() // CS1599 - { - return null; - } +- **CS8786**: *Calling convention of 'convention' is not compatible with 'convention'.* +- **CS8806**: *The calling convention of 'convention' is not supported by the language.* +- **CS8807**: *'specifier' is not a valid calling convention specifier for a function pointer.* +- **CS8808**: *'modifier' is not a valid function pointer return type modifier. Valid modifiers are 'ref' and 'ref readonly'.* +- **CS8809**: *A return type can only have one 'modifier' modifier.* - public ArgIterator Test2() // CS1599 - { - return null; - } -} -``` +Function pointer declarations include a calling convention and optional return type modifiers. The compiler validates these options. For the full rules, see [Function pointers](../unsafe-code.md#function-pointers). -## CS1958 +- Change either the method's calling convention or the function pointer type's calling convention so they match (**CS8786**). When you assign a method to a function pointer, the calling conventions must be compatible. For example, a method using `Cdecl` can't be assigned to a function pointer declared with `Stdcall`. +- Use a supported calling convention in the function pointer declaration (**CS8806**). The language supports `managed`, `unmanaged`, and specific unmanaged conventions such as `Cdecl`, `Stdcall`, `Thiscall`, and `Fastcall`. +- Replace the invalid specifier with one of the supported calling convention keywords: `managed`, `unmanaged`, `Cdecl`, `Stdcall`, `Thiscall`, or `Fastcall` (**CS8807**). You can also use `unmanaged` with a custom calling convention type in square brackets. +- Use only `ref` or `ref readonly` as the return type modifier (**CS8808**). Other modifiers, such as `out` or `in`, aren't valid for function pointer return types. +- Remove the duplicate return type modifier so only one `ref` or `ref readonly` appears (**CS8809**). The compiler allows at most one return type modifier on a function pointer declaration. -Object and collection initializer expressions may not be applied to a delegate creation expression +## Function pointer usage restrictions -A delegate has no members like a class or struct has, and so there's nothing for an object initializer to initialize. If you encounter this error, it's probably because there are braces after the delegate creation expression. Remove the braces and this error disappears. +- **CS8789**: *The type of a local declared in a fixed statement cannot be a function pointer type.* +- **CS8909**: *Comparison of function pointers might yield an unexpected result, since pointers to the same function may be distinct.* +- **CS8911**: *Using a function pointer type in this context is not supported.* -The following code produces CS1958: +The compiler restricts how function pointer types can be used in certain contexts. For the full rules, see [Function pointers](../unsafe-code.md#function-pointers). -```csharp -// cs1958.cs -public class MemberInitializerTest -{ - delegate void D(); - public static void GenericMethod() { } - public static void Run() - { - D genD = new D(GenericMethod) { }; // CS1958 - // Try the following line instead - // D genD = new D(GenericMethod); - } -} -``` +- Change the local variable type in the `fixed` statement to a data pointer type instead of a function pointer type (**CS8789**). The `fixed` statement pins managed objects in memory for data access. Function pointers represent code addresses, not data, and can't be pinned. +- Avoid comparing function pointers for equality (**CS8909**). This warning indicates that comparing function pointers with `==` or `!=` might produce unexpected results. The runtime might return different pointers for the same function due to implementation details such as thunking or JIT compilation. To suppress the warning when you confirm the comparison is intentional, use `#pragma warning disable CS8909`. +- Move the function pointer usage to a supported context (**CS8911**). Function pointer types can't be used in certain positions, such as attribute arguments or `typeof` expressions. Restructure the code to avoid using function pointer types in unsupported contexts. From 057b4c5c3bb045af74ee3b2a6f5363be0001e967 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 28 Apr 2026 14:17:54 -0400 Subject: [PATCH 4/6] Update docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../compiler-messages/delegate-function-pointer-diagnostics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md index af5b1fe715f9b..46563ffe2460c 100644 --- a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -135,7 +135,7 @@ When you assign a method to a function pointer by using the address-of (`&`) ope - Adjust the method's signature so its parameter types, return type, and parameter count match the function pointer type (**CS8757**). Unlike delegates, function pointers don't support implicit conversions between compatible method signatures. The match must be exact. - Align the `ref`, `out`, or `in` modifiers between the method's parameters and the function pointer type's parameters (**CS8758**). Each parameter's ref kind must match exactly. A `ref` parameter can't satisfy an `in` or `out` position in the function pointer type. - Change the target method to `static` (**CS8759**). Function pointers can only point to static methods because they represent raw function addresses without an associated object instance. -- Add the `&` operator before the method group when assigning to a function pointer (**CS8787**). Unlike delegates, function pointers require the explicit address-of operator: `delegate* ptr = &MyMethod;`. +- Add the `&` operator before the method group when assigning to a function pointer (**CS8787**). Unlike delegates, function pointers require the explicit address-of operator: `delegate* ptr = &MyMethod;`. - Use a static method instead of an extension method with a receiver (**CS8788**). The `&` operator requires a direct method reference. Extension methods called on an instance have an implicit receiver that can't be captured in a function pointer. - Remove the `&` operator and use delegate syntax instead, or change the target type from a delegate to a function pointer (**CS8811**). The `&` operator produces a function pointer, not a delegate. To assign a method group to a delegate type, omit the `&` and use standard delegate creation syntax. From fcdb58d5794b7407b67f0bb0890be87a30b6fe39 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 28 Apr 2026 14:27:52 -0400 Subject: [PATCH 5/6] respond to review --- .../delegate-function-pointer-diagnostics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md index 46563ffe2460c..a31f5bbf0aa90 100644 --- a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -150,8 +150,8 @@ When you assign a method to a function pointer by using the address-of (`&`) ope Function pointer declarations include a calling convention and optional return type modifiers. The compiler validates these options. For the full rules, see [Function pointers](../unsafe-code.md#function-pointers). - Change either the method's calling convention or the function pointer type's calling convention so they match (**CS8786**). When you assign a method to a function pointer, the calling conventions must be compatible. For example, a method using `Cdecl` can't be assigned to a function pointer declared with `Stdcall`. -- Use a supported calling convention in the function pointer declaration (**CS8806**). The language supports `managed`, `unmanaged`, and specific unmanaged conventions such as `Cdecl`, `Stdcall`, `Thiscall`, and `Fastcall`. -- Replace the invalid specifier with one of the supported calling convention keywords: `managed`, `unmanaged`, `Cdecl`, `Stdcall`, `Thiscall`, or `Fastcall` (**CS8807**). You can also use `unmanaged` with a custom calling convention type in square brackets. +- Use a supported calling convention in the function pointer declaration (**CS8806**). The language supports `managed` and `unmanaged`. For a specific unmanaged convention, use the `unmanaged` keyword with the convention in square brackets, such as `unmanaged[Cdecl]`, `unmanaged[Stdcall]`, `unmanaged[Thiscall]`, or `unmanaged[Fastcall]`. +- Replace the invalid specifier with a supported calling convention (**CS8807**). Use `managed`, `unmanaged`, or `unmanaged` with a calling convention type in square brackets (for example, `unmanaged[Cdecl]`). - Use only `ref` or `ref readonly` as the return type modifier (**CS8808**). Other modifiers, such as `out` or `in`, aren't valid for function pointer return types. - Remove the duplicate return type modifier so only one `ref` or `ref readonly` appears (**CS8809**). The compiler allows at most one return type modifier on a function pointer declaration. From 8ad43b2feb66c652047a3d989952354e0242ae0e Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 29 Apr 2026 13:30:28 -0400 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com> Co-authored-by: Bill Wagner --- .../delegate-function-pointer-diagnostics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md index a31f5bbf0aa90..7d89c76571f91 100644 --- a/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md +++ b/docs/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics.md @@ -1,5 +1,5 @@ --- -title: "Resolve errors and warnings related to delegate and function pointer declarations and uses" +title: "Resolve errors using delegates and function pointers" description: "This article helps you diagnose and correct compiler errors and warnings related to delegate and function pointer declarations and uses" f1_keywords: - "CS0059" @@ -53,7 +53,7 @@ ms.date: 04/27/2026 ai-usage: ai-assisted --- -# Resolve errors and warnings for delegate and function pointer declarations +# Resolve errors and warnings for delegate and function pointers This article covers the following compiler errors and warnings: