1

I am trying to create map using Esri.ArcGISRuntime.Xamarin.Forms nuget. For this I have created new project in Xamarin.Forms and installed this nuget. Then I have write this code:

Initialize Map key in App.xaml.cs

public partial class App : Application
{
   public App()
   {
       InitializeComponent();

       Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "my_api_key";
       MainPage = new MainPage();
   }
}

MainPage.xaml: Map UI

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:vm="clr-namespace:ArcGis_POC"
             x:Class="ArcGis_POC.MainPage">
    <ContentPage.BindingContext>
        <vm:MainPageViewModel />
    </ContentPage.BindingContext>
    <StackLayout>
        <esriUI:MapView x:Name="MyMapView" />
    </StackLayout>
</ContentPage>

MainPage.xaml.cs

public partial class MainPage : ContentPage
{
    public MainPageViewModel thisVm;

    public MainPage()
    {
        InitializeComponent();

        thisVm = ((MainPageViewModel)BindingContext);
        thisVm.SetupMap();
    }
}

MainPageViewModel

public class MainPageViewModel : BaseViewModel
{
    private Map _map;
    public Map Map
    {
        get { return _map; }
        set
        {
            _map = value;
            OnPropertyChanged();
        }
    }

    public void SetupMap()
    {
        // Create a new map with a 'topographic vector' basemap.
        Map = new Map(BasemapStyle.ArcGISTopographic);
    }
}

When I am trying to run thi46application in UWP with x64/x86 setup it gives this error. Anyone know how to fix this?

System.BadImageFormatException
  HResult=0x80131058
  Message=Could not load file or assembly 'Esri.ArcGISRuntime, Version=100.13.0.0, 
  Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'. Reference assemblies should not be loaded for
  execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
  Source=ArcGis_POC

In Android it runs but shows blank white screen.

Divyesh
  • 2,085
  • 20
  • 35
  • BadImageFormatException normally means that there is a conflict in bitness. Like you are compiling it into a 64bit app but the dependency you use is strictly 32bit for example. So check if the nuget package you use is only valid to use in a certain bitness and then adapt to that. – Ralf Jan 17 '22 at 11:18
  • I have installed latest stable version it supports all 3 platforms (iOS, Android, UWP). If it had some conflict then it will not get installed at first place. – Divyesh Jan 17 '22 at 11:43
  • 1
    Still BadImageFormatException indicates an assemblies is referenced that isn't compatible with the platform it is tried to be used on. Bitness is one case the other one is platform itself. Referencing the ios assembly on android for example. – Ralf Jan 17 '22 at 11:46

1 Answers1

0

According to the nuget page, you should install the appropriate nuget in each platform.

  • In cross-platform project, install Esri.ArcGISRuntime.Xamarin.Forms.
  • In UWP project, install Esri.ArcGISRuntime.UWP. Etc.

The common functionality in Esri.ArcGISRuntime will then be automatically installed, as a dependency of the platform-specific nuget.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • I have tried to install nuget in UWP project it gives this error: Severity Code Description Project File Line Suppression State Error NU1202 Package Esri.ArcGISRuntime.UWP 100.13.0 is not compatible with uap10.0.16299 (UAP,Version=v10.0.16299) / win10-arm64-aot. Package Esri.ArcGISRuntime.UWP 100.13.0 supports: uap10.0.18362 (UAP,Version=v10.0.18362) – Divyesh Jan 18 '22 at 04:07