# ArgumentException when trying to use OpenStreetMapOverlay

**URL:** <https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631>\
**Category:** WPF\
**Created:** [August 11, 2017, 3:04pm UTC](https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631 "2017-08-11T15:04:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Louchez](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/49beb7/32.png) [@Eric\_Louchez](https://community.thinkgeo.com/u/Eric_Louchez)\
**Post date:** [August 11, 2017, 3:04pm UTC](https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631/1 "2017-08-11T15:04:34Z")

</div>

I just used the instructions for setting up ThinkGeo for wpf (version 10.1.1).

I tried adding an OpenStreetMap overlay and started getting ArgumentExceptions.

So I simplified the code to this:

```
var osmOverlay = new OpenStreetMapOverlay();
Map1.Overlays.Add(osmOverlay);

```

By registering to the events on osmOverlay, I can determine that the tile gets downloaded just fine, however when it tries to draw it, I get this exception:

```
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at cSQ =.eSQ =.CreateDefault(Int32 width, Int32 height)
at ThinkGeo.MapSuite.Drawing.GeoImage.CreateNewNativeImage(Int32 width, Int32 height)
at ThinkGeo.MapSuite.Portable.PclGraphicsFactory.GetStretchedImage(GeoImage image, DrawingRectangleF targetRectangle, DrawingRectangleF sourceRectangle)
at ThinkGeo.MapSuite.Wpf.OpenStreetMapLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Layers.Layer.ZyU=(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Layers.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Wpf.LayerTile.81U= (Layer layer, ThreadSafetyLevel threadSaftyLevel, GeoCanvas geoCanvas, Collection`1 labelsInAllLayers)
at ThinkGeo.MapSuite.Wpf.LayerTile.8lU= (Layer layer, ThreadSafetyLevel threadSafetyLevel, GeoCanvas geoCanvas, Collection`1 labelsInAllLayers, Action`4 action)
at ThinkGeo.MapSuite.Wpf.LayerTile.DrawCore(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
```

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [August 14, 2017, 10:59am UTC](https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631/2 "2017-08-14T10:59:15Z")

</div>

Hi Eric,

We build a simple sample, which based on 10.1.1, and it looks everything works well. [OpenStreetMapDemo.zip](https://community.thinkgeo.com/uploads/default/original/3X/2/a/2adccc79f90986ee6c5ea8b8ed2e0ef528b8187d.zip) (9.7 KB)

Could you please modify our sample and reproduce the exception? So we can look into what’s the problem.

Regards,

Don

---

<div class="post-metadata">

**Author:** ![Eric\_Louchez](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/49beb7/32.png) [@Eric\_Louchez](https://community.thinkgeo.com/u/Eric_Louchez)\
**Post date:** [August 14, 2017, 4:22pm UTC](https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631/3 "2017-08-14T16:22:20Z")

</div>

Hello Don,

I was essentially using the wrong projection.

I had this:

```
map.MapUnit = GeographyUnit.DecimalDegree;
var osmOverlay = new OpenStreetMapOverlay();
map.Overlays.Add(osmOverlay);
map.CurrentExtent = new ThinkGeo.MapSuite.Shapes.RectangleShape(0, 78, 30, 26);
map.Refresh();

```

This is from the getting started sample which seems to use 4326, I made sure everything was getting reprojected to 3857 and it all works superbly well (with tile caching enable).

Thank you.

---

<div class="post-metadata">

**Author:** ![Ethan](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ethan/32/19964_2.png) [@Ethan](https://community.thinkgeo.com/u/Ethan)\
**Post date:** [August 15, 2017, 2:49am UTC](https://community.thinkgeo.com/t/argumentexception-when-trying-to-use-openstreetmapoverlay/8631/4 "2017-08-15T02:49:40Z")

</div>

Hi Eric,

I am glad to hear that works.

Any question please feel free to let us know.

Regards,

Don
