MonoTouch.Foundation.MonoTouchException has been thrown Objective-C exception thrown. Name: NSInternalInconsistencyException - c#

I seem to be getting this issue whenever I run my iOS app within Xamarin.
MonoTouch.Foundation.MonoTouchException has been thrown
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: ’NSBundle ... (loaded)' with name ‘RouteMeViewController'
I am trying to replace a GoogleMapsViewController with a RouteMeViewController using the Objective C library and Binder in an app that I was given to work on. My AppDelegate looks like this:
namespace ExampleApp.iOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
RouteMeViewController viewController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new RouteMeViewController ();
window.RootViewController = viewController;
window.MakeKeyAndVisible ();
return true;
}
}
RouteMeViewController
namespace ExampleApp.iOS
{
public partial class RouteMeViewController : UIViewController
{
RMMapView MapView { get; set; }
public RouteMeViewController () : base ("RouteMeViewController", null)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
MapView = new RMMapView(View.Frame, new RMOpenStreetMapSource().Handle);
MapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
if (UIScreen.MainScreen.Scale > 1.0)
MapView.AdjustTilesForRetinaDisplay = true;
Add (MapView);
}
}
}
Any help or direction is much appreciated, thank you!

It seems you're missing a designer file in the resources of your solution. Even if you programmatically create controls and views, you need a designer file where they need to be drawn in, even if it's just an empty designer file. For IOS, you can use XCode for that. You can create files with the .xib extension. They will be compiled on your device, and the resulting file has the extension .nib. Make sure the target of the .xib file is the correct viewController of your project, else you'll still get the error.
I hope this helps. Good luck!

It is 2023 and this problem still appease for xamarion.IOS
and working fine for xamarion.Android
I'm using the last xamarin forms version 5.0.0.2545
this answer solves my problem
I put a lot of codes after InitializeComponent();
to solve the problem just put MainPage = new MainPage(); directly after InitializeComponent(); in your App.xaml.cs
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
The problem now it will directly go to the page without reading the other codes
so to solve this move your code to another page,empty page or splash screen page and put your code in it like
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MySplashScreenPage());
}

Related

How to deal with System.TypeLoadException in the app.xaml.cs in xamarin.forms?

Sorry to bother you, but I've come across a error in my code I don't how to deal with.
Whenever I try to run my app, I get faced with this:
System.TypeLoadException: 'Could not resolve type with token 01000019
from typeref (expected class
'Xamarin.Forms.Xaml.Diagnostics.VisualDiagnostics' in assembly
'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=null')'
It states it occurs when the InitializeComponent(); is called in the constructor of App.xaml.cs.
Constructor in question:
public App()
{
//Line throwing the error
InitializeComponent();
MainPage = new NavigationPage(new Login.LogonFinal()); //Defines what page the app opens on when starting
}
App.xaml.cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace NEA_I_MDL
{
public partial class App : Application
{
static Databases.AccountDatabaseController AccountDatabaseVar;
public App()
{
//Line throwing the error
InitializeComponent();
MainPage = new NavigationPage(new Login.LogonFinal()); //Defines what page the app opens on when starting
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
public static Databases.AccountDatabaseController AccountDatabaseFunc
{
get
{
if(AccountDatabaseVar == null)
{
AccountDatabaseVar = new Databases.AccountDatabaseController();
}
return AccountDatabaseVar;
}
}
}
}
Thank you for reading, any tips/assistance will be a huge help for ineptly written code.
Can I ask that you please
Make sure you dont have different versions of the same Nugets in your solution.
Clean & Rebuild your Project
If That doesn't work for you try delete all your obj and bin folders and rebuild.
This usually happens because of Updates or version conflicts In my case atleast.
And do you mind showing us the LoginFinal Method?
I think you can just call Login
MainPage = new NavigationPage(new Login);

How is Setup class instantiated in MVVMCross in Xamarin?

I'm starting learning MVVM cross, In the android app, I have a splash screen class:
[Activity(MainLauncher = true,
Label = "#string/app_name",
Theme = "#style/Theme.Splash",
NoHistory = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashScreen : MvxSplashScreenActivity
{
public SplashScreen() : base(Resource.Layout.SplashScreen)
{
}
}
and this is the Setup class:
public class Setup : MvxAndroidSetup
{
protected Setup(Context applicationContext) : base(applicationContext)
{
}
protected override IMvxApplication CreateApp()
{
return null;
}
}
the problem is that the debugger doesn't hit the constructor of the Setup Class, instead I get "An unhandled exception" after the constructor of the splash screen
EDIT
I've already defined the App class in the PCL project:
public class App : MvxApplication
{
public override void Initialize()
{
base.Initialize();
}
also defined the AppStart:
public class AppStart : MvxNavigatingObject, IMvxAppStart
{
public async void Start(object hint = null)
{
//hardcoded login for this demo
//var userService = Mvx.Resolve<IUserDataService>();
//await userService.Login("gillcleeren", "123456");
ShowViewModel<MainViewModel>();
}
}
The main reason behind this project is to understand the sequence of code required and executed by MVVM Cross, so I provide the minimum code till it runs successfully without runtime errors.
Update
I have read your code again more thoroughly and I can see the issue now. You defined the constructor of the Setup class as protected, which makes it invisible for activation.
On MvvmCross for Android the magic happens inside MvxAndroidSetupSingleton class (see the source code here) which searches for the Setup type you defined. The FindSetupType method looks for your defined Setup class first and then inside the CreateSetup method Activator.CreateInstance is used to build the Setup instance. The CreateInstance method variant used however searches only for public constructors, which means it doesn't find your protected one. The result is that it cannot build the Setup class and crashes.
Original answer
The reason this happens is that you have no Core libary that would define the MvvmCross App class and would initialize other required setup. I suggest you to start with a simple tutorial or to look into the official sample projects to see what is necessary to make MvvmCross work in a Xamarin.Android app.

MVVM-Cross + Xamarin - Having Trouble with mvx CreateViewControllerFor()

I am developing an IOS application with Xamarin using MvvmCross.
I want to use a tab bar to navigate between my Views. I want to have only 1 storyboard per View and want to navigate and call my views from code.
I've overridden the MvxStoryboardViewsContainer Method CreateViewOfTyp() like the following:
protected override IMvxTouchView CreateViewOfType(Type viewType,
MvxViewModelRequest request)
{
var storyboardAttribute = viewType.GetCustomAttribute<FromStoryboardAttribute>();
if (storyboardAttribute == null) {
return base.CreateViewOfType(viewType, request);
}
string storyboardName = storyboardAttribute.StoryboardName ?? viewType.Name;
return
(IMvxTouchView)
UIStoryboard.FromName(storyboardName, NSBundle.MainBundle).InstantiateInitialViewController();
}
Evrytime I try creating my tab bar I call this Method a try to create a View from my model.
The Problem I am encountering here is that UIStoryboard I instantiate is of type UIViewController and not MvxViewController (therefor the app crashes when it tries to cast).
The actual Controller in question however, should be an MvxViewController!
[FromStoryboard("WorklistView")]
public partial class WorklistViewController :
MvxViewController<WorklistViewModel>
{
public WorklistViewController (IntPtr handle) : base (handle)
{
}
}
I'm not sure what i'm missing? Why is the Controller i get a UIViewController and not the MvxViewController it should be?
Thing is I found a lot about what i am trying to do but i can't figure out what i'm doing different.
I found my mistake and it was quite a stupid one.
My designer class had a different namespace then my controller; god knows why...
Well, it's solved now.

Xamarin.Forms: Use of GetMainPage()

I'm currently reading the navigation section from An Introduction to Xamarin.Forms. One should use the GetMainPage() method. But how should that be used?
The default implementation of the app delegate looks like the following:
Applicaton Delegate:
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init ();
LoadApplication (new App ());
return base.FinishedLaunching (app, options);
}
}
App:
public class App : Application
{
public App ()
{
MainPage = GetMainPage ();
}
public static Page GetMainPage()
{
var mainNav = new NavigationPage(new ListExample());
return mainNav;
}
}
I got it managed to use the GetMainPage()method instead of getting
Application windows are expected to have a root view controller at the end of application launch
If I look into the (old?) examples (example1, example2) the app delegate is different and a CreateViewController() method is available. In my case it is not!
What is the correct way of loading the root page on to the stack?
You don't have to use GetMainPage(); that's just a method you create. The way X.Forms works these days is: it exposes a MainPage property in the Xamarin.Forms Application class. You set this to an instance of a Page. How you create that page is up to you. You can either use
this.MainPage = new ContentPage { Content = ... }
or you create one file per page (which IMHO is best for maintainability):
this.MainPage = new MyLoginPage();
or you use helper methods which create your pages:
this.MainPage = this.GetMainPage();
The main page is the first page of your Forms application. You can set the MainPage property to a different value to show another page.
Earlier versions of Forms used different approaches and not all samples have been updated yet. Now all platforms only need a call to the Forms Init() method and a call to LoadApplication() instead of creating a view controller, an activity or a page (WP8).

Error to push a ViewController from other project

In the first project I have a UIButton. When I touch it, will be open other UIViewController from another project. But I have a problem:
Here's is my code to the first project, I will use it to call other UIViewcontroller from another project
public partial class SomeSoluctionViewController : UIViewController
{
public SomeSoluctionViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
PushedClassController pushedclass = PushedClass.AppDelegate.Storyboard.InstantiateViewController ("PushedClass") as PushedClassController;
CallButton.TouchUpInside += (object sender, EventArgs e) => {
this.NavigationController.PushViewController (pushedclass, true);
};
// Perform any additional setup after loading the view, typically from a nib.
}
}
I use PushViewController as Xamarin's site instructed
I instanciate the second class with the identifier.
On PushedClassController’s AppDelegate:
public static UIStoryboard Storyboard = UIStoryboard.FromName ("MainStoryboard", null);
I use it above.
Here's is the pushedView from the second project:
namespace PushedClass
{
** [Register ("PushedClass")]**
public partial class PushedClassController : UIViewController
{
public PushedClassController (IntPtr handle) : base (handle)
{
}
}
}
Registred with "PushedClass"
The log: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Storyboard () doesn't contain a view controller with identifier 'PushedClass'
Open the pushed project in xamarin.
Select the view controller you want to display by clicking on the black bar at the bottom.
In the designers property pad under identity specify a unique ID for Storyboard ID and Restoration ID to PushedClass.

Categories

Resources