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

2

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?

Effeminate answered 17/11, 2021 at 20:38 Comment(0)
E
40

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.

Effeminate answered 17/11, 2021 at 20:38 Comment(3)
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)Thermit
This is a good bug to investigate. Do you know why?Sonnysonobuoy
The plugin is not maintaned anymore ... One should use the one from Xamarin.Essentials. I didn't investigate more into this.Thermit
S
0

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

This issue will be fixed by updating the Main.cs file from:

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

to:

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

iOS API 12

public static void Main (string[] args, string principalClassName, string delegateClassName);

The above methods excepts to receive the string type.

iOS API 17

public static void Main (string[] args, Type? principalClassName, Type? delegateClassName);

Now the API is excepting to pass the Type instead of string. Still both are available for use

enter image description here

Svend answered 10/5 at 6:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.