C# Compiler Error
CS0261 – Partial declarations of ‘type’ must be all classes, all structs, or all interfaces
Reason for the Error
You’ll get this error in your C# code when you have declared the partial type on different types of constructs in various places.
For example, lets try to compile the below code snippet.
using System; namespace DeveloperPubNamespace { partial class class1 { } partial struct class1 { } class Program { public static void Main() { Console.WriteLine("Welcome"); } } }
You’ll receive the error code CS0261 when you try to build the C# program because you have declared the class “class1” and applied partial modifier on it and simultaneously, you have also declared a struct with the same name and marked it as partial.
Error CS0261 Partial declarations of ‘class1’ must be all classes, all record classes, all structs, all record structs, or all interfaces DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 9 Active
Solution
You can fix this error in your C# program by ensuring that partial declarations is made for the same type.