Search code examples
c#iosxamarin.iosxamarinxamarin-studio

Warning CS0114: `AnApp.AppDelegate.Self' hides inherited member


Today I updated to Xamarin.iOS 8.6.0.51. Now I get the following warning:

Warning CS0114: AnApp.AppDelegate.Self' hides inherited member MonoTouch.Foundation.NSObject.Self'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword (CS0114)

In my AppDelegate.cs I have defined the following property/field:

public static AppDelegate Self { get; private set; }

Than I set it in this way to get a reference to the app delegate (like proposed in this thread):

AppDelegate.Self = this;

This worked before the update. I use this to instantiate some view controllers from the storyboard and some other things (network activity indicator, ...). What do I have to change to get this working? Don't I need this anymore or should I rename Self?


Solution

  • It means the base class of AppDelegate have the member named Self too, compiler warns you that you may be unknowingly hiding the base class member.

    If you know what you're doing then you can safely suppress the warning using new keyword.

    public static new AppDelegate Self { get; private set; }
    

    That makes absolutely no difference whatsoever, without the new keyword also your App will work the same. It just tells the c# compiler that I'm intentionally using the same name for the member and I'm interested in hiding the base class member.