C# Error CS0126 – An object of a type convertible to ‘type’ is required

C# Compiler Error

CS0126 – An object of a type convertible to ‘type’ is required

Reason for the Error

You will receive this error when the signature of a property specifies the return type and you don’t return the value of the specified type in your C# code.

For example, try compiling the below code snippet.

namespace DeveloperPublishNamespace
{
    public class Employee
    {
        public int Name
        {
            set
            {
            }
            get
            {
                return;  
            }
        }
    }

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

We have an Employee class with the property “Name”. The property has a getter which just calls return without specifying the value or type that it needs to return. This will result in the below error.

Error CS0126 An object of a type convertible to ‘int’ is required ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 12 Active

C# Error CS0126 – An object of a type convertible to 'type' is required

Solution

When you are using a getter for a property, ensure that you return the value too.