C# Error CS0755 – Both partial method declarations must be extension methods or neither may be an extension method

C# Error

CS0755 – Both partial method declarations must be extension methods or neither may be an extension method

Reason for the Error & Solution

Both partial method declarations must be extension methods or neither may be an extension method.

A partial method consists of a defining declaration (signature) and an optional implementing declaration (body). If the defining declaration is an extension method, the implementing declaration, if one is defined, must also be an extension method. And if the defining method is not an extension method, the implementing must not be one either.

To correct this error

  1. Either remove the this modifier from one of the parts, or add it to the other.

Example

The following example generates CS0755:

// cs0755.cs  
    public static partial class Ext  
    {  
        static partial void Part(this C c); //Extension method  
  
        // Typically the implementing declaration is in a separate file.  
        static partial void Part(C c) //CS0755  
        {  
        }  
    }  
  
    public partial class C  
    {  
        public static int Main()  
        {  
            return 1;  
        }  
    }  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...