# V12 NullReferenceException when adding to MapView

**URL:** <https://community.thinkgeo.com/t/v12-nullreferenceexception-when-adding-to-mapview/9889>\
**Category:** WPF\
**Created:** [August 20, 2020, 2:55pm UTC](https://community.thinkgeo.com/t/v12-nullreferenceexception-when-adding-to-mapview/9889 "2020-08-20T14:55:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Hartman](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/m/87869e/32.png) [@Matt\_Hartman](https://community.thinkgeo.com/u/Matt_Hartman)\
**Post date:** [August 20, 2020, 2:55pm UTC](https://community.thinkgeo.com/t/v12-nullreferenceexception-when-adding-to-mapview/9889/1 "2020-08-20T14:55:17Z")

</div>

Hello, I have some code that seemed to work prior to the upgrade to V12 involving MapView.

I am attempting to add an Overlay like this:

```
FirstMap = new MapView();
FirstMap.Overlays?.Add(new LayerOverlay()); // Crash here

```

I am getting a NullReferenceException everytime I try to .add to this list, I crash out with this exception:

 ![crash](https://community.thinkgeo.com/uploads/default/original/3X/3/7/37f678dcd1b0a2bab663d0a434cfaca57f4b27ae.png)

Is there something else I need to do now before adding to the Overlays list?

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![Frank4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/frank4/32/25224_2.png) [@Frank4](https://community.thinkgeo.com/u/Frank4)\
**Post date:** [August 20, 2020, 7:13pm UTC](https://community.thinkgeo.com/t/v12-nullreferenceexception-when-adding-to-mapview/9889/2 "2020-08-20T19:13:26Z")

</div>

Matt,  
If you use the wpf mapview programmatically. You need add the map the the wpf container.

```
        FirstMap = new MapView();
        mainGrid.Children.Add(FirstMap); // Add the map to the wpf container. MainGrid is a wpf grid
        FirstMap.Loaded += FirstMap_Loaded;

```

After map loaded you could add your overlays.

```
private void FirstMap_Loaded(object sender, RoutedEventArgs e)
        {
            FirstMap.MapUnit = GeographyUnit.Meter;
            FirstMap.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000); ;
            FirstMap.Overlays?.Add(new LayerOverlay());
        }

```

Thanks

Frank
