ThinkGeo.com    |     Documentation    |     Premium Support

On iOS NullReferenceException at ThinkGeo.UI.XamarinForms.MapView..ctor

Morning.

As the title states on iOS I am getting a NullReferenceException at ThinkGeo.UI.XamarinForms.MapView…ctor. It is working fine on droid.

It is a Xamarin Forms app I am building with both a Droid and iOS projects. I have almost zero code in the platform projects.
The layout of the app is within a Xamarin Forms shell where I have a few pages and one contains your map control. Currently it is simple and very similar to your samples. A few layers with a handful of features.
On Android this has been working very nicely. I have just shifted over to iOS and I am getting the error on the pages init. Very simple page and I do use XAML.
I use the MVVM pattern and I pass the map control into the backing VM.
The xaml is

<ContentPage.Content>
        <ThinkGeo:MapView x:Name="mapView"
                          VerticalOptions="FillAndExpand"
                          MapLongPress="mapView_MapLongPress" />
    </ContentPage.Content>

and the code behind is

public MapPage()
        {
            InitializeComponent();
            MapPageViewModel = new MapPageViewModel(mapView);
            BindingContext = MapPageViewModel;
        }

The exception raised is on the InitializeComponent(); call.

The inner exception details are: (NOTE: -snip- is me removing stuff not required to be seen)
{System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NullReferenceException: Object reference not set to an instance of an object at ThinkGeo.UI.XamarinForms.MapView…ctor () [0x00030] in <1c709128f19f4e40990c9608d8dcd160>:0 at -snip-.Map.MapPage.InitializeComponent () [0x00023] in -snip-\obj\Debug\netstandard2.0\Map\MapPage.xaml.g.cs:26 at -snip-.Map.MapPage…ctor () [0x0003a] in -snip-\Map\MapPage.xaml.cs:30 at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&) at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:936 — End of inner exception stack trace —

Here are the details of my environment:
I am running it on a sim at iOS 14.4.

Microsoft Visual Studio Professional 2019
Version 16.9.4
VisualStudio.16.Release/16.9.4+31205.134
Microsoft .NET Framework
Version 4.8.04084

Xamarin 16.9.000.273 (d16-9@1bba9e0)

Xamarin.iOS and Xamarin.Mac SDK 14.14.2.5 (3836759d4)

ThinkGeo.UI.XamarinForms.iOS v12.3.10

Forms v4.8.0.1687

Xcode 12.4

I am currently running using an evaluation licence which has many more days before expiry.
I am happy to provide further details if required.

Cheers
Chris …

Good Morning.

I am wondering about the progress on this issue?
Is there any additional data I can provide to assist?

Cheers
Chris …

Hello.

I have been playing around with this issue further … creating a small repo case and have discovered the following.

I am creating a very small repo app and this time I have been developing mostly using the iOS platform of a Xamarin Forms app. After adding in the MapView control and yet to supply a temp licence file I ran up the app.

Now the doco at:
Quickstart Guides - ThinkGeo Docs
states that you should receive an exception of “A Licence is needed”. Now this is true on Android but on iOS I get the exception as stated in the previous posts above. null ref in ctor of control.

I am wondering if the issue here is the where and how I placed the licence file and also how the iOS library handles this scenario?

Looking over your samples I appear to be placing the iOS licence file in the correct location.

Are you able to confirm that when no licence file is supplied the exception above is what you get or do you get the “A Licence is needed” exception as doco states?

I am using v12 of the Nu-gets.

Regards
Chris …

Hello all.

It has been quite some time since original posting and there has not been any response on this.
Have I submitted the question incorrectly?

The map product is quite nice but if it does not work on iOS it is not too much use to us.

Regards
Chris …

Chris,

Is this happening on a deployed app or debugging on a virtual machine or read device? I will check the code to see if that error message is in the iOS version of map control. It is possible that this is a licensing issue.

Chris,

There was a line missing in the in the iOS project, file AppDelegate.cs. I included all the lines but the key one is the second where we add the dependency service for iOSMapViewAdapter.

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                global::Xamarin.Forms.Forms.Init();
                Xamarin.Forms.DependencyService.Register<ThinkGeo.UI.XamarinForms.iOS.iOSMapViewAdapter>();
                LoadApplication(new App());

                return base.FinishedLaunching(app, options);
            }