# Error while loading JSON style with Vector .mbtiles file

**URL:** <https://community.thinkgeo.com/t/error-while-loading-json-style-with-vector-mbtiles-file/10361>\
**Category:** ThinkGeo UI for Desktop\
**Created:** [August 25, 2023, 11:56am UTC](https://community.thinkgeo.com/t/error-while-loading-json-style-with-vector-mbtiles-file/10361 "2023-08-25T11:56:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enea](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Enea](https://community.thinkgeo.com/u/Enea)\
**Post date:** [August 25, 2023, 11:56am UTC](https://community.thinkgeo.com/t/error-while-loading-json-style-with-vector-mbtiles-file/10361/1 "2023-08-25T11:56:59Z")

</div>

Hello,

I’m trying to load a 450MB .mbtiles file coupled with a pre-delivered JSON-Style.  
I’m using the following dataset:

- [https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json](https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte.vt/style.json)
- [https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.leichte-basiskarte.vt/v3.0.0/ch.swisstopo.leichte-basiskarte.vt.mbtiles](https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.leichte-basiskarte.vt/v3.0.0/ch.swisstopo.leichte-basiskarte.vt.mbtiles)

And here below is my code, which throws a NullreferenceException (see below codebase) when trying to load the map/style.

Can you please tell me if I’m doing something wrong or if the library has some problems with the provided data?  
I tested both json and .mbtiles with QGIS and Maptiler, and they work fine.

Thanks!

private void MapView\_Loaded(object sender, RoutedEventArgs e)

```
    {
        // It is important to set the map unit first to either feet, meters or decimal degrees.
        mapView.MapUnit = GeographyUnit.Meter;
        // Create a new overlay that will hold our new layer
        LayerOverlay layerOverlay = new LayerOverlay();
        // Create the background world maps using vector tiles stored locally in our MBTiles file and also set the styling though a json file

        ThinkGeoMBTilesLayer mbTilesLayer = new ThinkGeoMBTilesLayer( @"E:\Desktop-Maps\ThinkGeoVectorTiles\Resources\ch.swisstopo.leichte-basiskarte.vt.mbtiles", new Uri(@"E:\Desktop-Maps\ThinkGeoVectorTiles\Resources\leichte-basiskarte.json"));

        mbTilesLayer.Projection = new Projection(2056);
        layerOverlay.Layers.Add(mbTilesLayer);

        try {
            layerOverlay.Open();
            // Add the overlay to the map
            mapView.Overlays.Add(layerOverlay);
            // Set the current extent of the map to an area in the data
            mapView.CurrentExtent = mbTilesLayer.GetBoundingBox();
            layerOverlay.Close();
        } catch(Exception ex) {
            Console.WriteLine(ex.StackTrace);
        }
        // Refresh the map.
        mapView.Refresh();
    }

```

An unhandled exception of type ‘System.ArgumentNullException’ occurred in ThinkGeo.Core.dll: ‘Value cannot be null.’  
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)  
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)  
at EhU=.9zI=.9TI=(JObject jsonObject)  
at EhU=.9zI=.hxU=(JObject jsonObject)  
at ThinkGeo.Core.StyleJsonDocument.Parse(Byte[] styleJsonBytes)  
at ThinkGeo.Core.ThinkGeoMBTilesLayer.lCs=()  
at ThinkGeo.Core.ThinkGeoMBTilesLayer.OpenCore()  
at ThinkGeo.Core.Layer.Open()  
at ThinkGeo.Core.LayerOverlay.OpenCore()  
at ThinkGeo.Core.Overlay.Open()  
at ThinkGeoVectorTiles.MainWindow.MapView\_Loaded(Object sender, RoutedEventArgs e) in E:\POCS\Desktop-Maps\ThinkGeoVectorTiles\MainWindow.xaml.cs:line 46  
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)  
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)  
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)  
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)  
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)  
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)  
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()  
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()  
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)  
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)  
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)  
at System.Windows.Interop.HwndTarget.OnResize()  
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)  
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)  
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)  
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)  
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)  
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)  
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)  
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

---

<div class="post-metadata">

**Author:** ![ThinkGeo\_Products](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@ThinkGeo\_Products](https://community.thinkgeo.com/u/ThinkGeo_Products)\
**Post date:** [August 28, 2023, 7:36pm UTC](https://community.thinkgeo.com/t/error-while-loading-json-style-with-vector-mbtiles-file/10361/2 "2023-08-28T19:36:38Z")

</div>

Hi Enea,

Thanks for your question, but the ThinkGeoMBTilesLayer is a custom format and does not work with other providers.

However, I know you’ve had questions in the past with the Swiss Topo data via WMTS and we’re looking into that further. I hope we can find a solution for you in the near future.

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![ThinkGeo\_Products](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@ThinkGeo\_Products](https://community.thinkgeo.com/u/ThinkGeo_Products)\
**Post date:** [August 31, 2023, 5:52pm UTC](https://community.thinkgeo.com/t/error-while-loading-json-style-with-vector-mbtiles-file/10361/3 "2023-08-31T17:52:42Z")

</div>

Hi Enea,

There’s a new build (13.2.0-beta019) that has a fix for your previous ticket you submitted regarding the WmtsLayer not working with the Swiss topo service. There was a {Time} parameter that the topo service used slightly different than other services we had seen in the past.

I hope this solution works and I’ll send a separate email with the sample code.

Thanks,  
John
