C# Error CS0764 – Both partial method declarations must be unsafe or neither may be unsafe

C# Error

CS0764 – Both partial method declarations must be unsafe or neither may be unsafe

Reason for the Error & Solution

Both partial method declarations must be unsafe or neither may be unsafe

A partial method consists of a defining declaration (signature) and an optional implementing declaration (body). If the defining declaration has the unsafe modifier, the implementing declaration must also have it. Conversely, if the implementing declaration has the unsafe modifier, the defining declaration must also.

To correct this error

  1. Assuming that the defining declaration is correct, add or remove the unsafe modifier from the implementing declaration to match the defining declaration.

Example

// cs0764.cs  
//  Compile with: /target:library /unsafe  
public partial class C  
{  
    partial void Part();  
    unsafe partial void Part() //CS0764  
    {  
    }  
  
    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...