C# Error CS0249 – Do not override object.Finalize. Instead, provide a destructor

C# Compiler Error

CS0249 – Do not override object.Finalize. Instead, provide a destructor.

Reason for the Error

You’ll receive this error in your C# program when you are trying to override the Finalize method that is defined in the System.Object class.

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

namespace DeveloperPubNamespace
{
   class Program
    {
        public class Employee
        {
            protected override void Finalize() 
            {

            }
        }
        public static void Main()
        {
        }
    }
}

You will receive the error code CS0249 in your C# program because we are trying to override the Finalize() method in the Employee class.

Error CS0249 Do not override object.Finalize. Instead, provide a destructor. DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 7 Active

C# Error CS0249 – Do not override object.Finalize. Instead, provide a destructor

Solution

To fix the error code CS0249 in your C# program, replace the Finalize override method with the destructor method as shown below.

namespace DeveloperPubNamespace
{
   class Program
    {
        public class Employee
        {
            ~ Employee() 
            {

            }
        }
        public static void Main()
        {

        }
    }
}