From e534278a4a67e530d01002bd198923b5982350db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Jul 2025 21:04:45 +0000 Subject: [PATCH 1/4] Initial plan From 0dab6700a04f7448618c618d1f3d216801846b0e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Jul 2025 21:19:31 +0000 Subject: [PATCH 2/4] Add detailed explanation and examples for CS0759 compiler error Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../compiler-messages/partial-declarations.md | 17 ++++++ .../partial-declarations/CS0759Examples.cs | 52 +++++++++++++++++++ .../partial-declarations.csproj | 8 +++ 3 files changed, 77 insertions(+) create mode 100644 docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs create mode 100644 docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj diff --git a/docs/csharp/language-reference/compiler-messages/partial-declarations.md b/docs/csharp/language-reference/compiler-messages/partial-declarations.md index 6563d19b8e1c5..bc47411e943ab 100644 --- a/docs/csharp/language-reference/compiler-messages/partial-declarations.md +++ b/docs/csharp/language-reference/compiler-messages/partial-declarations.md @@ -250,6 +250,23 @@ Certain `partial` method declarations don't require an *implementing declaration When a partial method includes an implementing declaration, both declarations must be identical. Exactly one implementing declaration can be defined. +**CS0759** occurs when you have an implementing declaration (a partial method with a body) but no corresponding defining declaration (the signature without a body). Every partial method with an implementation must have both: + +1. A *defining declaration*: the method signature without a body, as mentioned in the [Partial members](#partial-members) section. +2. An *implementing declaration*: the method signature with a body. + +The following example shows code that generates CS0759: + +:::code language="csharp" source="./snippets/partial-declarations/CS0759Examples.cs" id="IncorrectExample"::: + +To fix this error, add the defining declaration: + +:::code language="csharp" source="./snippets/partial-declarations/CS0759Examples.cs" id="CorrectExample"::: + +You can also place both declarations in the same partial class section: + +:::code language="csharp" source="./snippets/partial-declarations/CS0759Examples.cs" id="AlternativeCorrect"::: + ## Partial properties The following errors indicate mistakes in your partial property or indexer declarations: diff --git a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs new file mode 100644 index 0000000000000..ac01629a2c57c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs @@ -0,0 +1,52 @@ +using System; + +namespace CS0759Examples +{ + // + // This will cause CS0759: No defining declaration found for implementing declaration of partial method + // Uncomment the class below to see the CS0759 error: + /* + public partial class ExampleClass + { + // ERROR: This is an implementing declaration without a corresponding defining declaration + partial void MyMethod() // CS0759 + { + Console.WriteLine("Implementation without definition"); + } + } + */ + // + + // + // Correct way: Provide both the defining declaration and implementing declaration + public partial class CorrectExampleClass + { + // Defining declaration (signature without body) + partial void MyMethod(); + } + + public partial class CorrectExampleClass + { + // Implementing declaration (signature with body) + partial void MyMethod() + { + Console.WriteLine("This works correctly"); + } + } + // + + // + // Alternative correct approach: defining and implementing in same partial class + public partial class AlternativeExampleClass + { + // Defining declaration + partial void MyMethod(); + + // Implementing declaration in same partial class section + partial void MyMethod() + { + Console.WriteLine("This also works correctly"); + } + } + // +} \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj new file mode 100644 index 0000000000000..4c49d32c3fbed --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj @@ -0,0 +1,8 @@ + + + + net8.0 + enable + + + \ No newline at end of file From b5bc3ac6a3111281b04cced5e7398e228b822afd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:16:08 +0000 Subject: [PATCH 3/4] Update target framework to .NET 9 in partial-declarations project Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../snippets/partial-declarations/partial-declarations.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj index 4c49d32c3fbed..e33d07d003c30 100644 --- a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj +++ b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/partial-declarations.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable From db209a3a4891d8361381c6dcd73eb4fd705ef0e2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 5 Aug 2025 19:59:24 +0000 Subject: [PATCH 4/4] Address review feedback: simplify CS0759 explanation and fix code comment punctuation Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --- .../compiler-messages/partial-declarations.md | 5 +---- .../snippets/partial-declarations/CS0759Examples.cs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/partial-declarations.md b/docs/csharp/language-reference/compiler-messages/partial-declarations.md index bc47411e943ab..9dbcfd384ebfd 100644 --- a/docs/csharp/language-reference/compiler-messages/partial-declarations.md +++ b/docs/csharp/language-reference/compiler-messages/partial-declarations.md @@ -250,10 +250,7 @@ Certain `partial` method declarations don't require an *implementing declaration When a partial method includes an implementing declaration, both declarations must be identical. Exactly one implementing declaration can be defined. -**CS0759** occurs when you have an implementing declaration (a partial method with a body) but no corresponding defining declaration (the signature without a body). Every partial method with an implementation must have both: - -1. A *defining declaration*: the method signature without a body, as mentioned in the [Partial members](#partial-members) section. -2. An *implementing declaration*: the method signature with a body. +**CS0759** occurs when you have an *implementing declaration* (a partial method with a body) but no corresponding *defining declaration* (the method signature without a body). Every partial method with an implementation must have both declarations. The following example shows code that generates CS0759: diff --git a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs index ac01629a2c57c..a954358dce03a 100644 --- a/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs +++ b/docs/csharp/language-reference/compiler-messages/snippets/partial-declarations/CS0759Examples.cs @@ -3,7 +3,7 @@ namespace CS0759Examples { // - // This will cause CS0759: No defining declaration found for implementing declaration of partial method + // This will cause CS0759: No defining declaration found for implementing declaration of partial method. // Uncomment the class below to see the CS0759 error: /* public partial class ExampleClass