# Random NullReferenceException

**URL:** <https://community.thinkgeo.com/t/random-nullreferenceexception/2708>\
**Category:** WPF\
**Created:** [June 29, 2010, 7:40am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708 "2010-06-29T07:40:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [June 29, 2010, 7:40am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/1 "2010-06-29T07:40:43Z")

</div>

Hello,

I'm&nbsp;encoutering&nbsp;another&nbsp;random&nbsp;problem,&nbsp;and&nbsp;I&nbsp;cannot&nbsp;figure&nbsp;where&nbsp;it&nbsp;comes&nbsp;from&nbsp;:

Some&nbsp;times,&nbsp;when&nbsp;loading&nbsp;the&nbsp;map&nbsp;for&nbsp;the&nbsp;first&nbsp;time,&nbsp;I&nbsp;get&nbsp;this&nbsp;exception&nbsp;:

System.NullReferenceException:&nbsp;Der&nbsp;Objektverweis&nbsp;wurde&nbsp;nicht&nbsp;auf&nbsp;eine&nbsp;Objektinstanz&nbsp;festgelegt.  
  
&nbsp;&nbsp;&nbsp;bei&nbsp;ThinkGeo.MapSuite.WpfDesktopEdition.GdiPlusLayerTile.x72e495c788ab064e(Object&nbsp;xe0292b9ed559da7d,&nbsp;RunWorkerCompletedEventArgs&nbsp;xfbf34718e704c6bc)  
  
&nbsp;&nbsp;&nbsp;bei&nbsp;System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs&nbsp;e)  
  
&nbsp;&nbsp;&nbsp;bei&nbsp;System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object&nbsp;arg)  
  
&nbsp;&nbsp;&nbsp;bei&nbsp;System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate&nbsp;callback,&nbsp;Object&nbsp;args,&nbsp;Boolean&nbsp;isSingleParameter)  
  
&nbsp;&nbsp;&nbsp;bei&nbsp;System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object&nbsp;source,&nbsp;Delegate&nbsp;callback,&nbsp;Object&nbsp;args,&nbsp;Boolean&nbsp;isSingleParameter,&nbsp;Delegate&nbsp;catchHandler)

Translation&nbsp;:&nbsp;Object&nbsp;reference&nbsp;not&nbsp;set&nbsp;to&nbsp;an&nbsp;instance&nbsp;of&nbsp;an&nbsp;object.

This&nbsp;exception&nbsp;is&nbsp;thrown&nbsp;many&nbsp;times,&nbsp;I&nbsp;think&nbsp;it&nbsp;could&nbsp;be&nbsp;one&nbsp;exception&nbsp;per&nbsp;loaded&nbsp;tile.&nbsp;

I'm&nbsp;using&nbsp;the&nbsp;WmsOverlay,&nbsp;with&nbsp;a&nbsp;custom&nbsp;WmsServer,&nbsp;and&nbsp;I've&nbsp;created&nbsp;a&nbsp;CustomWfsLayer&nbsp;which&nbsp;inherits&nbsp;from&nbsp;featureLayern,&nbsp;in&nbsp;order&nbsp;to&nbsp;load&nbsp;features&nbsp;from&nbsp;a&nbsp;Wfs&nbsp;Server.&nbsp;I&nbsp;think&nbsp;this&nbsp;exception&nbsp;can&nbsp;come&nbsp;from&nbsp;one&nbsp;of&nbsp;thoses&nbsp;two&nbsp;layers,&nbsp;but&nbsp;I'm&nbsp;not&nbsp;sure.

Once&nbsp;again,&nbsp;it's&nbsp;pretty&nbsp;difficult&nbsp;to&nbsp;give&nbsp;you&nbsp;some&nbsp;more&nbsp;informations,&nbsp;cause&nbsp;I&nbsp;cannont&nbsp;break&nbsp;in.&nbsp;As&nbsp;the&nbsp;callstack&nbsp;says,&nbsp;this&nbsp;exception&nbsp;comes&nbsp;probably&nbsp;from&nbsp;an&nbsp;Asynchron&nbsp;Worker,&nbsp;but&nbsp;where&nbsp;exactly&nbsp;?

It&nbsp;is&nbsp;possible&nbsp;that&nbsp;it&nbsp;comes&nbsp;from&nbsp;my&nbsp;code,&nbsp;but&nbsp;I&nbsp;don't&nbsp;have&nbsp;any&nbsp;informations&nbsp;on&nbsp;how&nbsp;to&nbsp;find&nbsp;it.&nbsp;Is&nbsp;there&nbsp;a&nbsp;problem&nbsp;with&nbsp;the&nbsp;pictures&nbsp;sent&nbsp;by&nbsp;the&nbsp;Wms&nbsp;Server&nbsp;?&nbsp;Or&nbsp;with&nbsp;the&nbsp;features&nbsp;sent&nbsp;by&nbsp;the&nbsp;Wfs&nbsp;Server&nbsp;?&nbsp;Or&nbsp;is&nbsp;it&nbsp;another&nbsp;Problem&nbsp;?

Any&nbsp;help&nbsp;or&nbsp;advice&nbsp;will&nbsp;be&nbsp;very&nbsp;helpfull,  
  
Thanks,  
  
Guillaume.

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [June 29, 2010, 8:28pm UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/2 "2010-06-29T20:28:07Z")

</div>

Hi&nbsp;Guillaume,&nbsp;  
&nbsp;&nbsp;  
&nbsp;To&nbsp;explain&nbsp;this&nbsp;issue,&nbsp;I’ll&nbsp;introduce&nbsp;you&nbsp;the&nbsp;tile&nbsp;system&nbsp;in&nbsp;the&nbsp;Wpf&nbsp;Desktop&nbsp;Edition.&nbsp;You&nbsp;know&nbsp;WmsOverlay&nbsp;and&nbsp;LayerOverlay&nbsp;are&nbsp;inheriting&nbsp;from&nbsp;TileOverlay&nbsp;and&nbsp;TileOverlay&nbsp;is&nbsp;formed&nbsp;by&nbsp;several&nbsp;tiles.&nbsp;This&nbsp;is&nbsp;the&nbsp;main&nbsp;difference&nbsp;from&nbsp;the&nbsp;Desktop&nbsp;Edition.&nbsp;So&nbsp;the&nbsp;we&nbsp;can&nbsp;get&nbsp;better&nbsp;user&nbsp;experience&nbsp;during&nbsp;panning&nbsp;and&nbsp;zooming.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;see&nbsp;you&nbsp;are&nbsp;using&nbsp;WmsOverlay&nbsp;for&nbsp;your&nbsp;custom&nbsp;server&nbsp;and&nbsp;a&nbsp;LayerOverlay&nbsp;for&nbsp;your&nbsp;custom&nbsp;feature&nbsp;layer.&nbsp;Here&nbsp;is&nbsp;the&nbsp;point.&nbsp;We&nbsp;have&nbsp;different&nbsp;tile&nbsp;objects&nbsp;work&nbsp;with&nbsp;different&nbsp;overlays;&nbsp;for&nbsp;example&nbsp;WmsOverlay&nbsp;fills&nbsp;with&nbsp;UriTile&nbsp;while&nbsp;LayerOverlay&nbsp;fills&nbsp;with&nbsp;GdiPlusLayerTile.&nbsp;  
&nbsp;&nbsp;  
&nbsp;From&nbsp;the&nbsp;exception&nbsp;you&nbsp;pasted,&nbsp;I&nbsp;can&nbsp;figure&nbsp;out&nbsp;the&nbsp;exception&nbsp;is&nbsp;from&nbsp;your&nbsp;LayerOverlay&nbsp;with&nbsp;your&nbsp;custom&nbsp;feature&nbsp;layer&nbsp;and&nbsp;the&nbsp;exception&nbsp;throws&nbsp;during&nbsp;the&nbsp;multithread&nbsp;to&nbsp;get&nbsp;the&nbsp;features&nbsp;from&nbsp;the&nbsp;your&nbsp;custom&nbsp;server.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Would&nbsp;you&nbsp;mind&nbsp;to&nbsp;send&nbsp;me&nbsp;a&nbsp;small&nbsp;sample&nbsp;so&nbsp;that&nbsp;I&nbsp;can&nbsp;recreate&nbsp;this&nbsp;issue.&nbsp;On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;you&nbsp;can&nbsp;try&nbsp;to&nbsp;set&nbsp;TileType&nbsp;to&nbsp;SingleTile&nbsp;for&nbsp;the&nbsp;LayerOverlay&nbsp;and&nbsp;try&nbsp;again.&nbsp;If&nbsp;the&nbsp;sample&nbsp;is&nbsp;private,&nbsp;please&nbsp;send&nbsp;to&nbsp;[support@thinkgeo.com](mailto:support@thinkgeo.com)&nbsp;and&nbsp;ask&nbsp;them&nbsp;to&nbsp;forward&nbsp;to&nbsp;me.&nbsp;  
&nbsp;&nbsp;  
&nbsp;As&nbsp;always,&nbsp;thanks&nbsp;for&nbsp;your&nbsp;reporting&nbsp;and&nbsp;I&nbsp;think&nbsp;your&nbsp;support&nbsp;makes&nbsp;our&nbsp;product&nbsp;powerful.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard&nbsp;

---

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [June 30, 2010, 1:22am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/3 "2010-06-30T01:22:19Z")

</div>

Hi&nbsp;Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;answer.&nbsp;  
&nbsp;I&nbsp;just&nbsp;tried&nbsp;to&nbsp;set&nbsp;the&nbsp;TileType&nbsp;to&nbsp;SingleTile&nbsp;for&nbsp;my&nbsp;Custom&nbsp;Overlay,&nbsp;but&nbsp;I&nbsp;had&nbsp;this&nbsp;exception&nbsp;again.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Then,&nbsp;I&nbsp;tried&nbsp;to&nbsp;create&nbsp;a&nbsp;sample&nbsp;application&nbsp;using&nbsp;a&nbsp;WmsOverlay&nbsp;and&nbsp;a&nbsp;my&nbsp;CustomWfsLayer,&nbsp;with&nbsp;my&nbsp;Wms&nbsp;and&nbsp;Wfs&nbsp;servers,&nbsp;but&nbsp;I&nbsp;cannot&nbsp;have&nbsp;this&nbsp;exception&nbsp;in&nbsp;this&nbsp;sample&nbsp;application.&nbsp;  
&nbsp;&nbsp;  
&nbsp;In&nbsp;my&nbsp;application,&nbsp;I&nbsp;just&nbsp;noticed&nbsp;that&nbsp;this&nbsp;Exception&nbsp;comes&nbsp;when&nbsp;I&nbsp;don’t&nbsp;display&nbsp;the&nbsp;CustomWfsLayer&nbsp;too.&nbsp;  
&nbsp;I’m&nbsp;using&nbsp;2&nbsp;InMemoryLayers&nbsp;in&nbsp;my&nbsp;application&nbsp;too,&nbsp;can&nbsp;this&nbsp;exception&nbsp;come&nbsp;from&nbsp;those&nbsp;layers&nbsp;?&nbsp;  
&nbsp;I’ll&nbsp;try&nbsp;to&nbsp;reproduce&nbsp;this&nbsp;Problem&nbsp;in&nbsp;my&nbsp;small&nbsp;application,&nbsp;but&nbsp;i&nbsp;seems&nbsp;a&nbsp;bit&nbsp;difficult&nbsp;to&nbsp;reproduce&nbsp;that&nbsp;easily.&nbsp;I’ll&nbsp;try.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Guillaume.&nbsp;  
&nbsp;&nbsp;  
&nbsp;P.S.&nbsp;I’ll&nbsp;have&nbsp;to&nbsp;say&nbsp;that&nbsp;this&nbsp;new&nbsp;WfsDesktopEdition&nbsp;has&nbsp;really&nbsp;a&nbsp;better&nbsp;user&nbsp;experience&nbsp;as&nbsp;the&nbsp;old&nbsp;one.&nbsp;It’s&nbsp;really&nbsp;good,&nbsp;thanks&nbsp;for&nbsp;that.

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [June 30, 2010, 2:58am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/4 "2010-06-30T02:58:32Z")

</div>

Guillaume,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;still&nbsp;cannot&nbsp;recreate&nbsp;your&nbsp;issue.&nbsp;So&nbsp;now&nbsp;I&nbsp;assume&nbsp;you&nbsp;have&nbsp;three&nbsp;overlays;&nbsp;one&nbsp;is&nbsp;the&nbsp;WmsOverlay,&nbsp;and&nbsp;a&nbsp;LayerOverlay&nbsp;which&nbsp;works&nbsp;with&nbsp;your&nbsp;cumstomWfsLayer,&nbsp;and&nbsp;the&nbsp;third&nbsp;one&nbsp;is&nbsp;a&nbsp;LayerOverlay&nbsp;with&nbsp;two&nbsp;InMemoryFeatureLayers.&nbsp;Because&nbsp;now&nbsp;I’m&nbsp;sure&nbsp;the&nbsp;exception&nbsp;is&nbsp;from&nbsp;GdiPlusLayerTile&nbsp;so&nbsp;we&nbsp;can&nbsp;exclude&nbsp;the&nbsp;WmsOverlay;&nbsp;and&nbsp;you&nbsp;have&nbsp;set&nbsp;the&nbsp;second&nbsp;LayerOverlay&nbsp;which&nbsp;works&nbsp;with&nbsp;you&nbsp;customWfsLayer&nbsp;to&nbsp;single&nbsp;tile;&nbsp;it&nbsp;won’t&nbsp;throw&nbsp;an&nbsp;exception&nbsp;as&nbsp;you&nbsp;pasted&nbsp;because&nbsp;single&nbsp;tile&nbsp;won’t&nbsp;draw&nbsp;in&nbsp;another&nbsp;thread.&nbsp;Now&nbsp;we&nbsp;have&nbsp;only&nbsp;one&nbsp;LayerOverlay&nbsp;left&nbsp;which&nbsp;might&nbsp;be&nbsp;the&nbsp;one&nbsp;to&nbsp;throw&nbsp;the&nbsp;exception.&nbsp;But&nbsp;I&nbsp;cannot&nbsp;figure&nbsp;out&nbsp;why.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Could&nbsp;you&nbsp;try&nbsp;to&nbsp;commend&nbsp;out&nbsp;the&nbsp;rest&nbsp;of&nbsp;your&nbsp;overlays&nbsp;and&nbsp;try&nbsp;to&nbsp;confirm&nbsp;if&nbsp;my&nbsp;guess&nbsp;is&nbsp;right.&nbsp;Then&nbsp;set&nbsp;the&nbsp;overlay&nbsp;to&nbsp;SingleTile&nbsp;to&nbsp;see&nbsp;if&nbsp;the&nbsp;exception&nbsp;still&nbsp;exists;&nbsp;if&nbsp;yes;&nbsp;please&nbsp;let&nbsp;me&nbsp;know&nbsp;the&nbsp;new&nbsp;exception&nbsp;message.&nbsp;  
&nbsp;&nbsp;  
&nbsp;On&nbsp;the&nbsp;other&nbsp;hand,&nbsp;I&nbsp;have&nbsp;found&nbsp;a&nbsp;potential&nbsp;issue&nbsp;which&nbsp;may&nbsp;throw&nbsp;this&nbsp;exception,&nbsp;but&nbsp;I&nbsp;cannot&nbsp;test&nbsp;for&nbsp;I&nbsp;cannot&nbsp;recreate&nbsp;the&nbsp;issue;&nbsp;so&nbsp;please&nbsp;get&nbsp;the&nbsp;latest&nbsp;version&nbsp;and&nbsp;have&nbsp;a&nbsp;try.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;and&nbsp;appreciate&nbsp;your&nbsp;testing.&nbsp;  
&nbsp;Howard

---

<div class="post-metadata">

**Author:** ![Guillaume](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@Guillaume](https://community.thinkgeo.com/u/Guillaume)\
**Post date:** [July 5, 2010, 1:20am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/5 "2010-07-05T01:20:57Z")

</div>

Hello&nbsp;Howard,&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;seems&nbsp;that&nbsp;setting&nbsp;the&nbsp;TileType&nbsp;to&nbsp;SingleTile&nbsp;for&nbsp;my&nbsp;InMemoryLayer&nbsp;solved&nbsp;the&nbsp;problem.&nbsp;  
&nbsp;I&nbsp;cannot&nbsp;be&nbsp;100%&nbsp;sure&nbsp;yet,&nbsp;because&nbsp;I&nbsp;cannot&nbsp;recreate&nbsp;this&nbsp;issue&nbsp;on&nbsp;demand,&nbsp;but&nbsp;I&nbsp;played&nbsp;for&nbsp;some&nbsp;hours&nbsp;yet&nbsp;with&nbsp;this&nbsp;SingleTile&nbsp;type,&nbsp;and&nbsp;I&nbsp;didn’t&nbsp;have&nbsp;this&nbsp;exception&nbsp;again.&nbsp;  
&nbsp;&nbsp;  
&nbsp;For&nbsp;now&nbsp;it&nbsp;is&nbsp;solved&nbsp;for&nbsp;me.&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;help&nbsp;once&nbsp;again.&nbsp;  
&nbsp;Guillaume.&nbsp;

---

<div class="post-metadata">

**Author:** ![Howard](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/h/90ced4/32.png) [@Howard](https://community.thinkgeo.com/u/Howard)\
**Post date:** [July 5, 2010, 1:28am UTC](https://community.thinkgeo.com/t/random-nullreferenceexception/2708/6 "2010-07-05T01:28:41Z")

</div>

Hi&nbsp;Guillaume,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;welcome;&nbsp;please&nbsp;let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;more&nbsp;queries.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Howard
