17

After upgrade my Xamarin.Forms version to 5.0.0.2244, I'm getting the following warning in Main.cs file inside my iOS project:

Method UIKit.UIApplication.Main is obsolete: Use the overload with Type instead of String parameters for type safety.

This my Main.cs file:

using UIKit;

namespace LindeGctMobileApplication.iOS
{
    public class Application
    {
        private static void Main(string[] args)
        {
            UIApplication.Main(args, null, "AppDelegate"); // << warning
        }
    }
}

What do I need to change to remove this warning?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Ângelo Polotto
  • 8,463
  • 2
  • 36
  • 37

1 Answers1

39

Class reference through a string is now deprecated. You need to change this line:

UIApplication.Main(args, null, "AppDelegate");

to this:

UIApplication.Main(args, null, typeof(AppDelegate));

In that way, you explicitly inform the type of the class.

Ângelo Polotto
  • 8,463
  • 2
  • 36
  • 37
  • As a hint: If I use the new approach the app crashes, when taking a picture with the `CrossMedia` plugin. The exception is: *There's no current active window (System.InvalidOperationException)* – testing Aug 03 '22 at 12:09
  • This is a good bug to investigate. Do you know why? – Ângelo Polotto Aug 03 '22 at 16:42
  • The plugin is not maintaned anymore ... One should use the one from Xamarin.Essentials. I didn't investigate more into this. – testing Aug 04 '22 at 10:45