Error: ‘Object.get’ must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.


Error: ‘Object.get’ must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.

Description: This error occurs when you have a property with only get accessor or an Automatic property with only get. The reason behind the auto generated properties with get can only access the value but cannot ever set the property value because we have no access to the internal storage of property.

Example: public static string StringNull { get; }

Solution: By defining a set accessor this error can be resolved.

Example: public static string StringNull { get; private set; }

Here private is the access modifier.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s