Compiler Error CS0546
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Compiler Error CS0546 

Error Message

'accessor' : cannot override because 'property' does not have an overridable set accessor

An attempt to override one of the accessor methods for a property failed because the accessor cannot be overridden. You can resolve this error by:

  • Adding a set accessor in the base class.

  • Removing the set accessor from the derived class.

  • Hiding the base class property by adding the new keyword in derived class's property.

  • Making the base class property virtual.

For more information, see Property Declaration and Using Properties (C# Programming Guide).

Example

The following sample generates CS0546.

// CS0546.cs
// compile with: /target:library
public class a
{
   public virtual int i
   {
      get
      {
         return 0;
      }
   }

   public virtual int i2
   {
      get
      {
         return 0;
      }

      set {}
   }
}

public class b : a
{
   public override int i
   {
      set {}   // CS0546 error no set
   }

   public override int i2
   {
      set {}   // OK
   }
}
Show:
© 2016 Microsoft