AnsweredAssumed Answered

Can't load Baspemaps and Operational Layer on a MapView control Xamarin.Forms when UWP project is in Release Mode.

Question asked by marceloctorresn on May 30, 2017
Latest reply on Jun 1, 2017 by mnielsen-esristaff

I'm developing an Xamarin.Forms mapping app to Android and UWP Platforms using ESRI ArcGISRuntime SDK .NET 100.0 . As part of the workflow the app loads a basemap and a lot of different operational layers based on ArcGIS Tiled and Dynamic Map Services. At almost all development time I wrote and tested code in Debug mode of Visual Studio 2017 and everything went right. But as part of testing time I made a Release apk and appx files to tester teams. The testers of Android version reported that installations went OK, but Windows 10 and Windows 10 Mobile testers reported that basemaps and operational layers did not load. Then I tested inside Visual Studio launching the UWP project in Release mode and I realized that it was true. On the other hand, to upload the application packages to the stores (Play Store and Windows Store) the app must me compiled in Release mode.

 

Checking the two configurations at project property window I noted there was a pair of differences among Debug and Release mode the "General / Compile with .NET Native tool chain" checkbox was not checked in the first case and checked in the second case:

Debug Configuration

Release Configuration

I wrote a lite version of the app to proof the point, and the behavior is the same: this is the code of the ViewModel class of the MapPage.xaml that does this part of the workflow:

using Esri.ArcGISRuntime.Mapping;
using Prism.Mvvm;
using Prism.Services;
using System;
using Xamarin.Forms;

/// <summary>
///
/// </summary>
namespace MapTest.ViewModels
{
  /// <summary>
  ///
  /// </summary>
  public class MapPageViewModel : BindableBase
  {
    private Map _map;

    /// <summary>
    ///
    /// </summary>
    public Map Map
    {
      get { return _map; }
      set { SetProperty(ref _map, value); }
    }

    private IPageDialogService dialogService;

    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    public IPageDialogService GetDialogService()
    {
      return dialogService;
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="value"></param>
    public void SetDialogService(IPageDialogService value)
    {
      dialogService = value;
    }

    /// <summary>
    ///
    /// </summary>
    public MapPageViewModel(IPageDialogService dialogService)
    {
      Map = new Map();
      SetDialogService(dialogService);
      AddLayers();
    }

    /// <summary>
    ///
    /// </summary>
    private void AddLayers()
    {
      try
      {
        Map.Basemap = Basemap.CreateTopographic();
        AddLayer("http://sampleserver5.arcgisonline.com/arcgis/rest/services/Elevation/WorldElevations/MapServer", "dynamic");
        ShowAlert("MapTest", "Finish");
      }
      catch (Exception ex)
      {
        ShowAlert("Exception", ex.Message);
      }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="url"></param>
    /// <param name="tipo"></param>
    private void AddLayer(string url, string tipo)
    {
      Layer layer = null;
      if (tipo == "tiled")
      {
        layer = new ArcGISTiledLayer(new Uri(url));
      }
      else if (tipo == "dynamic")
      {
        layer = new ArcGISMapImageLayer(new Uri(url));
      }

      try
      {
        this.Map.OperationalLayers.Add(layer);
        ShowAlert("MapTest", "layer Added.");
      }
      catch (Exception ex)
      {
        throw ex;
      }
    }

    /// <summary>
    /// /
    /// </summary>
    /// <param name="title"></param>
    /// <param name="message"></param>
    private void ShowAlert(string title, string message)
    {
      System.Diagnostics.Debug.WriteLine(message);
      Device.BeginInvokeOnMainThread(async () =>
      {
          await this.GetDialogService().DisplayAlertAsync(
          title,
          message,
          "Close");
      });
    }
  }
}

The complete solution is published at github in this address: https://github.com/marceloctorres/MapTest.

Someone can help me to find the solution or at least a workaround? I would appreciate it.

Marcelo.

Outcomes