C# Error CS0263 – Partial declarations of ‘type’ must not specify different base classes

C# Compiler Error

CS0263 – Partial declarations of ‘type’ must not specify different base classes

Reason for the Error

You’ll get this error in your C# code when you have defined the partial type with same name and each one of them has a different base class.

For example, lets try to compile the below code snippet.

using System;

namespace DeveloperPubNamespace
{
    public class BaseClass1
    {
        public string Name { get; set; }
    }

    public class BaseClass2
    {
        public string Name { get; set; }
    }

    public partial class class1 : BaseClass2
    {
    }

    public partial class class1 : BaseClass1
    {
    }
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Welcome");
        }
    }
}

You’ll receive the error code CS0263 when you try to build the above C# program because you have declared multiple partial types “class1” but each one inheriting from a different base class “BaseClass1” and “BaseClass2”

Error CS0263 Partial declarations of ‘class1’ must not specify different base classes DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 15 Active

C# Error CS0263 – Partial declarations of 'type' must not specify different base classes

Solution

When you define a type in partial declarations in your C# program, it is important to specify the same base types for each of the partial types.

You can fix the above program by specifying the same base class for both the partial type declarations as shown below.

using System;

namespace DeveloperPubNamespace
{
    public class BaseClass1
    {
        public string Name { get; set; }
    }

    public class BaseClass2
    {
        public string Name { get; set; }
    }

    public partial class class1 : BaseClass1
    {
    }

    public partial class class1 : BaseClass1
    {
    }
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Welcome");
        }
    }
}

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...