1

In my xamarin forms project I run my xamarin ios part for the first time, but getting the following Exception:

Foundation.MonoTouchException has been thrown Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named AppDelegate is loaded.

Screenshot: enter image description here

AppDelegate.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Foundation;
    using UIKit;

    namespace Myapp.iOS
    {
        // The UIApplicationDelegate for the application. This class is responsible for launching the 
        // User Interface of the application, as well as listening (and optionally responding) to 
        // application events from iOS.
        [Register("AppDelegate")]
        public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        {
            //
            // This method is invoked when the application has loaded and is ready to run. In this 
            // method you should instantiate the window, load the UI into it and then make the window
            // visible.
            //
            // You have 17 seconds to return from this method, or iOS will terminate your application.
            //
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                global::Xamarin.Forms.Forms.Init();
                LoadApplication(new App(""));

                return base.FinishedLaunching(app, options);
            }
        }
    }

Main.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Foundation;
    using UIKit;

    namespace Myapp.iOS
    {
        public class Application
        {
            // This is the main entry point of the application.
            static void Main(string[] args)
            {
                // if you want to use a different Application Delegate class from "AppDelegate"
                // you can specify it here.
                UIApplication.Main(args, null, "AppDelegate");
            }
        }
    }

Thanks in advance

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105
  • What is happening inside your `App.cs`? – Gerald Versluis Feb 15 '18 at 14:50
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) –  Feb 15 '18 at 14:51
  • In app.xaml.cs i am loading the mainpage, mainpage contains the login credentials – Sreejith Sree Feb 15 '18 at 14:57
  • @GeraldVersluis I edit the question with the exception screenshot – Sreejith Sree Feb 15 '18 at 15:01
  • The problem lies deeper. Your are calling a method somewhere which takes a parameter called `image` and you're putting a null value in there. From your screenshots I see a call to `FromPatternImage`? Also, try not to post errors as screenshots, posting the text makes it more searchable. – Gerald Versluis Feb 15 '18 at 15:04
  • I am not using FromPatternImage() in my project and not passing any image as an argument. – Sreejith Sree Feb 15 '18 at 15:19
  • Could you attach the code in App.cs and mainpage.cs – ColeX Feb 16 '18 at 06:28
  • @GeraldVersluis: Solve the system.argumentnullexception by setting the icon buildaction property to content, now getting a MonoTouchException. Question edited with AppDelegate.cs and Main.cs – Sreejith Sree Feb 16 '18 at 07:14
  • @ColeXia-MSFT Attach the Main.cs and AppDelegate.cs in the question – Sreejith Sree Feb 16 '18 at 07:53
  • @SreejithSree build action of image here should be set to BundleResource ,and we need App and Mainpage code in PCL not AppDelegate and Main – ColeX Feb 16 '18 at 07:57
  • https://stackoverflow.com/questions/47402126/no-class-named-appdelegate-is-loaded may helps. – ColeX Feb 16 '18 at 08:31

1 Answers1

0

I Solve this issue by setting the Build Action property of AppDelegate.cs to Combile

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105