Unable to use .mpk

799
2
Jump to solution
08-30-2016 05:47 AM
WayneChen
New Contributor

Working on 10.2.7 .net WPF with .mpk files from official samples and created on my own, I got the exception when calling localMapService.StartAsync().  The message shows "null class esri_runtimecore::Map_renderer::Symbol handle passed to interop function."  Have any idea how to fix this?  Thanks a lot.

0 Kudos
1 Solution

Accepted Solutions
PrashantPurohit
New Contributor

Hi Wayne. I guess you are using runtime sdk for .Net 10.2.7 since ArcGIS Runtime SDK 10.2.5 for WPF was the final release of this SDK. I understand that you are trying to load a map package and you get exception at localMapService.StartAsync() method. The below code should work for you:

using Esri.ArcGISRuntime.Controls;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.LocalServices;


namespace ArcGISApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{


CreateLocalServiceAndDynamicLayer();
}

private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
{
if (e.LoadError == null)
return;

Debug.WriteLine(string.Format("Error while loading layer : {0} - {1}", e.Layer.ID, e.LoadError.Message));
}

public async void CreateLocalServiceAndDynamicLayer()
{
try
{
LocalMapService localMapService = new LocalMapService(@"D:\Cases\2016\February\Chris\abc.mpk");
await localMapService.StartAsync();

ArcGISDynamicMapServiceLayer arcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer()
{
ID = "arcGISDynamicMapServiceLayer",
ServiceUri = localMapService.UrlMapService,
};

MyMapView.Map.Layers.Add(arcGISDynamicMapServiceLayer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

}
}

View solution in original post

0 Kudos
2 Replies
PrashantPurohit
New Contributor

Hi Wayne. I guess you are using runtime sdk for .Net 10.2.7 since ArcGIS Runtime SDK 10.2.5 for WPF was the final release of this SDK. I understand that you are trying to load a map package and you get exception at localMapService.StartAsync() method. The below code should work for you:

using Esri.ArcGISRuntime.Controls;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using Esri.ArcGISRuntime.Layers;
using Esri.ArcGISRuntime.LocalServices;


namespace ArcGISApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{


CreateLocalServiceAndDynamicLayer();
}

private void MyMapView_LayerLoaded(object sender, LayerLoadedEventArgs e)
{
if (e.LoadError == null)
return;

Debug.WriteLine(string.Format("Error while loading layer : {0} - {1}", e.Layer.ID, e.LoadError.Message));
}

public async void CreateLocalServiceAndDynamicLayer()
{
try
{
LocalMapService localMapService = new LocalMapService(@"D:\Cases\2016\February\Chris\abc.mpk");
await localMapService.StartAsync();

ArcGISDynamicMapServiceLayer arcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer()
{
ID = "arcGISDynamicMapServiceLayer",
ServiceUri = localMapService.UrlMapService,
};

MyMapView.Map.Layers.Add(arcGISDynamicMapServiceLayer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

}
}

0 Kudos
WayneChen
New Contributor

Thanks to Prashant Purohit

I also figure out that declaring <esri:GISDynamicMapServiceLayer Name="myLayer"/> in xaml and myLayer.ServiceUri = localMapService.UrlMapService in c# code won't work even though the localserver is running.

Conclusion: following Prashant Purohit's code(same as the official demo sample), dynamically creating a LocalMapService and GISDynamicMapServiceLayer in code is the right way.

0 Kudos