# Instance not valid exception thrown for GetFeaturesNearestTo

**URL:** <https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343>\
**Category:** WPF\
**Created:** [December 9, 2012, 6:18pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343 "2012-12-09T18:18:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [December 9, 2012, 6:18pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/1 "2012-12-09T18:18:48Z")

</div>

Hi

I'm&nbsp;getting&nbsp;an&nbsp;exception&nbsp;thrown&nbsp;when&nbsp;I&nbsp;call&nbsp;QueryTools.GetFeaturesNearestTo&nbsp;

Details&nbsp;below.&nbsp;Running&nbsp;v6.0.178.0.&nbsp;

If&nbsp;checked&nbsp;IsValid&nbsp;-&nbsp;returned&nbsp;True.

I&nbsp;tried&nbsp;MakeValid&nbsp;-&nbsp;still&nbsp;crashed.

&nbsp;

Works&nbsp;OK&nbsp;when&nbsp;I&nbsp;zoom&nbsp;into&nbsp;the&nbsp;map&nbsp;using&nbsp;box&nbsp;zoom.&nbsp;Fails&nbsp;when&nbsp;I&nbsp;quickly&nbsp;zoom&nbsp;in&nbsp;using&nbsp;ChangeScale.

&nbsp;

Any&nbsp;ideas?

&nbsp;

Here&nbsp;is&nbsp;the&nbsp;code:

Collection\<Feature\>&nbsp;features&nbsp;=&nbsp;featureLayer.QueryTools.GetFeaturesNearestTo(feature.ShapeFeature,&nbsp;

GeographyUnit.Meter,&nbsp;1,&nbsp;ReturningColumnsType.AllColumns);

&nbsp;

Here&nbsp;is&nbsp;the&nbsp;error&nbsp;message:

24144:&nbsp;This&nbsp;operation&nbsp;cannot&nbsp;be&nbsp;completed&nbsp;because&nbsp;the&nbsp;instance&nbsp;is&nbsp;not&nbsp;valid.&nbsp;Use&nbsp;MakeValid&nbsp;to&nbsp;convert&nbsp;the&nbsp;instance&nbsp;to&nbsp;a&nbsp;valid&nbsp;instance.&nbsp;Note&nbsp;that&nbsp;MakeValid&nbsp;may&nbsp;cause&nbsp;the&nbsp;points&nbsp;of&nbsp;a&nbsp;geometry&nbsp;instance&nbsp;to&nbsp;shift&nbsp;slightly.

&nbsp;

Here&nbsp;is&nbsp;the&nbsp;stack&nbsp;Trace:

&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.SqlServer.Types.SqlGeometry.ThrowIfInvalid()

&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.SqlServer.Types.SqlGeometry.STIntersects(SqlGeometry&nbsp;other)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.BaseShape.IntersectsCore(BaseShape&nbsp;targetShape)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.BaseShape.Intersects(BaseShape&nbsp;targetShape)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PolygonShape.GetDistanceToCore(BaseShape&nbsp;targetShape,&nbsp;GeographyUnit&nbsp;shapeUnit,&nbsp;DistanceUnit&nbsp;distanceUnit)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.BaseShape.GetDistanceTo(BaseShape&nbsp;targetShape,&nbsp;GeographyUnit&nbsp;shapeUnit,&nbsp;DistanceUnit&nbsp;distanceUnit)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureSource.IBQ=(Collection`1&nbsp;IRQ=,&nbsp;BaseShape&nbsp;IhQ=,&nbsp;GeographyUnit&nbsp;IxQ=,&nbsp;Int32&nbsp;JBQ=)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestToCore(BaseShape&nbsp;targetShape,&nbsp;GeographyUnit&nbsp;unitOfData,&nbsp;Int32&nbsp;maxItemsToFind,&nbsp;IEnumerable`1&nbsp;returningColumnNames)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(BaseShape&nbsp;targetShape,&nbsp;GeographyUnit&nbsp;unitOfFeatureSource,&nbsp;Int32&nbsp;maxItemsToFind,&nbsp;IEnumerable`1&nbsp;returningColumnNames)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(Feature&nbsp;targetFeature,&nbsp;GeographyUnit&nbsp;unitOfData,&nbsp;Int32&nbsp;maxItemsToFind,&nbsp;IEnumerable`1&nbsp;returningColumnNames)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesNearestTo(Feature&nbsp;targetFeature,&nbsp;GeographyUnit&nbsp;unitOfData,&nbsp;Int32&nbsp;maxItemsToFind,&nbsp;ReturningColumnsType&nbsp;returningColumnNamesType)

&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.QueryTools.GetFeaturesNearestTo(Feature&nbsp;targetFeature,&nbsp;GeographyUnit&nbsp;unitOfData,&nbsp;Int32&nbsp;maxItemsToFind,&nbsp;ReturningColumnsType&nbsp;returningColumnNamesType)

&nbsp;

Cheers

Steve

&nbsp;

---

<div class="post-metadata">

**Author:** ![Ryan](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@Ryan](https://community.thinkgeo.com/u/Ryan)\
**Post date:** [December 10, 2012, 4:22pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/2 "2012-12-10T16:22:10Z")

</div>

Hi&nbsp;Steve,&nbsp;  
  
  
  
Thanks&nbsp;for&nbsp;your&nbsp;post!&nbsp;  
  
  
  
There&nbsp;are&nbsp;a&nbsp;couple&nbsp;of&nbsp;ways&nbsp;we&nbsp;could&nbsp;move&nbsp;forward&nbsp;with&nbsp;this&nbsp;issue.&nbsp;The&nbsp;first&nbsp;option&nbsp;is&nbsp;to&nbsp;have&nbsp;you&nbsp;update&nbsp;to&nbsp;the&nbsp;latest&nbsp;daily&nbsp;Development&nbsp;Build&nbsp;as&nbsp;we&nbsp;did&nbsp;make&nbsp;some&nbsp;modifications&nbsp;to&nbsp;our&nbsp;implementation&nbsp;of&nbsp;the&nbsp;SqlServerSpatial110.dll&nbsp;back&nbsp;on&nbsp;the&nbsp;December&nbsp;6th.&nbsp;Note&nbsp;that&nbsp;this&nbsp;dll&nbsp;did&nbsp;not&nbsp;change,&nbsp;just&nbsp;our&nbsp;implementation&nbsp;of&nbsp;it&nbsp;as&nbsp;it&nbsp;relates&nbsp;to&nbsp;the&nbsp;GeometryLibrary.&nbsp;As&nbsp;this&nbsp;is&nbsp;easy&nbsp;to&nbsp;change&nbsp;I&nbsp;would&nbsp;first&nbsp;recommend&nbsp;swapping&nbsp;in&nbsp;at&nbsp;least&nbsp;the&nbsp;6.0.210.0&nbsp;version.&nbsp;  
  
  
  
If&nbsp;you&nbsp;still&nbsp;encounter&nbsp;this&nbsp;issue&nbsp;we&nbsp;will&nbsp;need&nbsp;to&nbsp;take&nbsp;a&nbsp;closer&nbsp;look&nbsp;at&nbsp;your&nbsp;data&nbsp;and&nbsp;see&nbsp;if&nbsp;indeed&nbsp;there&nbsp;is&nbsp;an&nbsp;Invalid&nbsp;shape.&nbsp;  
  
  
  
Let&nbsp;me&nbsp;know&nbsp;how&nbsp;the&nbsp;later&nbsp;version&nbsp;of&nbsp;the&nbsp;WPFEdition.dll&nbsp;and&nbsp;MapSuiteCore.dll&nbsp;work&nbsp;out.

Edit:&nbsp;You&nbsp;can&nbsp;get&nbsp;the&nbsp;latest&nbsp;Development&nbsp;Build&nbsp;of&nbsp;the&nbsp;WPF&nbsp;Desktop&nbsp;Edition&nbsp;from&nbsp;[helpdesk.thinkgeo.com](http://helpdesk.thinkgeo.com).

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [December 10, 2012, 4:28pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/3 "2012-12-10T16:28:55Z")

</div>

Hi&nbsp;Ryan&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;tried&nbsp;6.0.210.0&nbsp;and&nbsp;it&nbsp;behaved&nbsp;the&nbsp;same.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;inserted&nbsp;code&nbsp;to&nbsp;check&nbsp;if&nbsp;the&nbsp;shape&nbsp;IsValid&nbsp;and&nbsp;also&nbsp;to&nbsp;always&nbsp;call&nbsp;MakeValid&nbsp;but&nbsp;the&nbsp;exception&nbsp;was&nbsp;still&nbsp;thrown.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;don’t&nbsp;believe&nbsp;that&nbsp;it&nbsp;is&nbsp;due&nbsp;to&nbsp;an&nbsp;invalid&nbsp;shape.&nbsp;If&nbsp;I&nbsp;zoom&nbsp;in&nbsp;using&nbsp;a&nbsp;zoom&nbsp;box&nbsp;it&nbsp;all&nbsp;works&nbsp;well.&nbsp;It&nbsp;does&nbsp;not&nbsp;work&nbsp;when&nbsp;I&nbsp;zoom&nbsp;in&nbsp;quickly&nbsp;using&nbsp;change&nbsp;scale.&nbsp;I&nbsp;zoom&nbsp;in&nbsp;so&nbsp;quickly&nbsp;that&nbsp;the&nbsp;map&nbsp;does&nbsp;not&nbsp;have&nbsp;a&nbsp;chance&nbsp;to&nbsp;draw&nbsp;completely&nbsp;before&nbsp;I&nbsp;zoom&nbsp;in&nbsp;again.&nbsp;Could&nbsp;it&nbsp;be&nbsp;something&nbsp;to&nbsp;do&nbsp;with&nbsp;the&nbsp;rapid&nbsp;zooming?&nbsp;  
&nbsp;&nbsp;  
&nbsp;It&nbsp;will&nbsp;be&nbsp;very&nbsp;difficult&nbsp;for&nbsp;me&nbsp;to&nbsp;send&nbsp;you&nbsp;code&nbsp;to&nbsp;replicate&nbsp;this&nbsp;as&nbsp;the&nbsp;map&nbsp;is&nbsp;part&nbsp;of&nbsp;a&nbsp;larger&nbsp;system.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve&nbsp;

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [December 12, 2012, 2:06pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/4 "2012-12-12T14:06:26Z")

</div>

Hi&nbsp;Ryan&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;reverted&nbsp;back&nbsp;to&nbsp;v6.0.0.0&nbsp;and&nbsp;all&nbsp;works&nbsp;fine.&nbsp;So&nbsp;definitely&nbsp;nothing&nbsp;to&nbsp;do&nbsp;with&nbsp;bad&nbsp;shape&nbsp;data.&nbsp;Must&nbsp;be&nbsp;something&nbsp;to&nbsp;do&nbsp;with&nbsp;new&nbsp;Microsoft.SqlServer.Types.dll&nbsp;use.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![Edgar](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@Edgar](https://community.thinkgeo.com/u/Edgar)\
**Post date:** [December 12, 2012, 7:38pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/5 "2012-12-12T19:38:18Z")

</div>

Hi&nbsp;Steve,&nbsp;  
&nbsp;&nbsp;  
&nbsp;We&nbsp;upgraded&nbsp;the&nbsp;topology&nbsp;engine&nbsp;to&nbsp;Microsoft.SqlServer.Types&nbsp;after&nbsp;version&nbsp;6.0.37.0,&nbsp;this&nbsp;one&nbsp;is&nbsp;more&nbsp;restrict&nbsp;than&nbsp;the&nbsp;old&nbsp;one&nbsp;(NTS),&nbsp;so&nbsp;there&nbsp;must&nbsp;be&nbsp;some&nbsp;invalid&nbsp;feature&nbsp;through&nbsp;using&nbsp;the&nbsp;method,&nbsp;as&nbsp;your&nbsp;project&nbsp;is&nbsp;hard&nbsp;to&nbsp;send,&nbsp;could&nbsp;you&nbsp;please&nbsp;provide&nbsp;some&nbsp;info&nbsp;of&nbsp;the&nbsp;featureLayer&nbsp;and&nbsp;the&nbsp;feature&nbsp;you&nbsp;want&nbsp;to&nbsp;GetNearestTo?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Edgar

---

<div class="post-metadata">

**Author:** ![TIM1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/b782af/32.png) [@TIM1](https://community.thinkgeo.com/u/TIM1)\
**Post date:** [January 4, 2013, 11:11am UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/6 "2013-01-04T11:11:00Z")

</div>

I&nbsp;am&nbsp;having&nbsp;the&nbsp;same&nbsp;problem.&nbsp;My&nbsp;map&nbsp;will&nbsp;not&nbsp;load&nbsp;now&nbsp;with&nbsp;the&nbsp;newest&nbsp;version&nbsp;of&nbsp;6.0.222.&nbsp;I&nbsp;also&nbsp;updated&nbsp;the&nbsp;Microsoft.SqlServer.Types.dll.&nbsp;And&nbsp;it&nbsp;will&nbsp;work&nbsp;if&nbsp;I&nbsp;go&nbsp;back&nbsp;to&nbsp;version&nbsp;6.0.&nbsp;Not&nbsp;sure&nbsp;what&nbsp;to&nbsp;do&nbsp;now.

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [January 4, 2013, 10:59pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/7 "2013-01-04T22:59:58Z")

</div>

Hello&nbsp;TIM,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post,&nbsp;what’s&nbsp;the&nbsp;situation&nbsp;looks&nbsp;like&nbsp;in&nbsp;your&nbsp;side?&nbsp;How&nbsp;many&nbsp;overlays&nbsp;you&nbsp;have&nbsp;added&nbsp;to&nbsp;the&nbsp;map?&nbsp;Are&nbsp;all&nbsp;overlays&nbsp;can’t&nbsp;display&nbsp;or&nbsp;just&nbsp;some&nbsp;of&nbsp;them?&nbsp;Can&nbsp;you&nbsp;try&nbsp;to&nbsp;set&nbsp;the&nbsp;DrawingExceptionMode&nbsp;to&nbsp;ThrowException&nbsp;and&nbsp;see&nbsp;if&nbsp;any&nbsp;exception&nbsp;throwing&nbsp;out?&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;you&nbsp;can&nbsp;provide&nbsp;some&nbsp;sample&nbsp;that&nbsp;we&nbsp;can&nbsp;recreate&nbsp;the&nbsp;problem,&nbsp;we&nbsp;can&nbsp;track&nbsp;the&nbsp;root&nbsp;cause.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;inconvenience,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Dan2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@Dan2](https://community.thinkgeo.com/u/Dan2)\
**Post date:** [February 7, 2013, 8:37am UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/8 "2013-02-07T08:37:56Z")

</div>

&nbsp;We&nbsp;are&nbsp;getting&nbsp;a&nbsp;similar&nbsp;problem&nbsp;when&nbsp;trying&nbsp;to&nbsp;make&nbsp;a&nbsp;selection&nbsp;from&nbsp;a&nbsp;SHAPE&nbsp;file.&nbsp;Error&nbsp;shown&nbsp;below:&nbsp;-

&nbsp;

System.ArgumentException:&nbsp;"24144:&nbsp;This&nbsp;operation&nbsp;cannot&nbsp;be&nbsp;completed&nbsp;because&nbsp;the&nbsp;instance&nbsp;is&nbsp;not&nbsp;valid.&nbsp;Use&nbsp;MakeValid&nbsp;to&nbsp;convert&nbsp;the&nbsp;instance&nbsp;to&nbsp;a&nbsp;valid&nbsp;instance.&nbsp;Note&nbsp;that&nbsp;MakeValid&nbsp;may&nbsp;cause&nbsp;the&nbsp;points&nbsp;of&nbsp;a&nbsp;geometry&nbsp;instance&nbsp;to&nbsp;shift&nbsp;slightly."

&nbsp;

&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.SqlServer.Types.SqlGeometry.ThrowIfInvalid()

&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.SqlServer.Types.SqlGeometry.STWithin(SqlGeometry&nbsp;other)

&nbsp;

I&nbsp;attach&nbsp;a&nbsp;link&nbsp;to&nbsp;a&nbsp;SHP&nbsp;file&nbsp;we&nbsp;are&nbsp;trying&nbsp;to&nbsp;load,&nbsp;this&nbsp;is&nbsp;for&nbsp;the&nbsp;SE&nbsp;of&nbsp;England,&nbsp;we&nbsp;are&nbsp;trying&nbsp;to&nbsp;cut&nbsp;the&nbsp;data&nbsp;around&nbsp;London&nbsp;when&nbsp;the&nbsp;exception&nbsp;is&nbsp;thrown.&nbsp;&nbsp;This&nbsp;is&nbsp;a&nbsp;new&nbsp;issue&nbsp;since&nbsp;updating&nbsp;our&nbsp;build&nbsp;from&nbsp;v6.0.

SHAPE&nbsp;FILE&nbsp;LINK

yousendit.com/download/UW15ak8rZDVCSnJFdzhUQw

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [February 11, 2013, 10:42am UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/9 "2013-02-11T10:42:40Z")

</div>

Hello&nbsp;Dan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post,&nbsp;because&nbsp;we&nbsp;changed&nbsp;the&nbsp;default&nbsp;geometry&nbsp;engine&nbsp;from&nbsp;NTS&nbsp;to&nbsp;SqlType,&nbsp;but&nbsp;SqlType&nbsp;has&nbsp;more&nbsp;strict&nbsp;conditional,&nbsp;so&nbsp;this&nbsp;exception&nbsp;throws&nbsp;because&nbsp;some&nbsp;of&nbsp;your&nbsp;shapes&nbsp;can&nbsp;not&nbsp;pass&nbsp;the&nbsp;SqlType&nbsp;validate.&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;can&nbsp;switch&nbsp;back&nbsp;to&nbsp;NTS&nbsp;by&nbsp;using&nbsp;BaseShape.GeometryLibrary&nbsp;=&nbsp;GeometryLibrary.Managed&nbsp;at&nbsp;the&nbsp;beginning&nbsp;of&nbsp;your&nbsp;code.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;inconvenience,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Dan2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@Dan2](https://community.thinkgeo.com/u/Dan2)\
**Post date:** [February 11, 2013, 10:59am UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/10 "2013-02-11T10:59:16Z")

</div>

Hi&nbsp;Gary,&nbsp;  
&nbsp;&nbsp;  
&nbsp;By&nbsp;changing&nbsp;between&nbsp;NTS&nbsp;and&nbsp;SqlType,&nbsp;what&nbsp;other&nbsp;differences&nbsp;should&nbsp;we&nbsp;expect?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Dan

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [February 11, 2013, 11:31am UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/11 "2013-02-11T11:31:44Z")

</div>

Hello&nbsp;Dan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;There&nbsp;isn’t&nbsp;any&nbsp;big&nbsp;difference&nbsp;between&nbsp;NTS&nbsp;and&nbsp;SqlType&nbsp;result,&nbsp;just&nbsp;SqlType&nbsp;has&nbsp;more&nbsp;strict&nbsp;conditional,&nbsp;so&nbsp;we&nbsp;are&nbsp;considering&nbsp;using&nbsp;the&nbsp;SqlType&nbsp;at&nbsp;MapSuite&nbsp;7.0&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [February 11, 2013, 12:55pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/12 "2013-02-11T12:55:52Z")

</div>

Hi&nbsp;Gary&nbsp;  
&nbsp;&nbsp;  
&nbsp;What&nbsp;do&nbsp;you&nbsp;mean&nbsp;by&nbsp;"more&nbsp;strict&nbsp;conditional"&nbsp;?&nbsp;I&nbsp;have&nbsp;been&nbsp;trying&nbsp;to&nbsp;fix&nbsp;this&nbsp;issue&nbsp;for&nbsp;5&nbsp;months.&nbsp;My&nbsp;customers&nbsp;data&nbsp;triggers&nbsp;this&nbsp;issue&nbsp;with&nbsp;the&nbsp;new&nbsp;geometry&nbsp;engine&nbsp;along&nbsp;with&nbsp;at&nbsp;least&nbsp;2&nbsp;other&nbsp;people&nbsp;in&nbsp;this&nbsp;thread.&nbsp;What&nbsp;should&nbsp;I&nbsp;be&nbsp;telling&nbsp;my&nbsp;customer&nbsp;to&nbsp;check&nbsp;for?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<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:** [February 11, 2013, 10:10pm UTC](https://community.thinkgeo.com/t/instance-not-valid-exception-thrown-for-getfeaturesnearestto/3343/13 "2013-02-11T22:10:51Z")

</div>

&nbsp;Hi&nbsp;guys,

&nbsp;  
Sorry&nbsp;for&nbsp;the&nbsp;delay,&nbsp;to&nbsp;see&nbsp;the&nbsp;stack&nbsp;trace&nbsp;of&nbsp;your&nbsp;exceptions,&nbsp;it&nbsp;must&nbsp;be&nbsp;caused&nbsp;by&nbsp;the&nbsp;upgrade&nbsp;of&nbsp;the&nbsp;shapes&nbsp;core&nbsp;in&nbsp;our&nbsp;development&nbsp;branch.&nbsp;After&nbsp;the&nbsp;major&nbsp;release&nbsp;6.0.0.0,&nbsp;we&nbsp;integrated&nbsp;the&nbsp;SqlTypes&nbsp;as&nbsp;our&nbsp;default&nbsp;shape&nbsp;core.&nbsp;(It&nbsp;is&nbsp;used&nbsp;to&nbsp;be&nbsp;NTS,&nbsp;NettopolygySuite.)&nbsp;SqlTypes&nbsp;has&nbsp;better&nbsp;performance&nbsp;for&nbsp;converting&nbsp;between&nbsp;well&nbsp;known&nbsp;binary&nbsp;and&nbsp;shapes.&nbsp;Also&nbsp;its&nbsp;topology&nbsp;calculation&nbsp;is&nbsp;more&nbsp;accurate&nbsp;and&nbsp;much&nbsp;faster&nbsp;and&nbsp;some&nbsp;other&nbsp;advantages.&nbsp;This&nbsp;change&nbsp;improves&nbsp;performance&nbsp;of&nbsp;the&nbsp;entire&nbsp;mapsuite&nbsp;product&nbsp;line.&nbsp;  
&nbsp;  
But&nbsp;it&nbsp;also&nbsp;takes&nbsp;downside&nbsp;on&nbsp;another&nbsp;hand.&nbsp;SqlTypes&nbsp;has&nbsp;more&nbsp;restrict&nbsp;rules&nbsp;than&nbsp;our&nbsp;origanl&nbsp;NTS&nbsp;when&nbsp;doing&nbsp;topology&nbsp;calculations.&nbsp;For&nbsp;example,&nbsp;when&nbsp;using&nbsp;NTS,&nbsp;if&nbsp;one&nbsp;shape&nbsp;is&nbsp;invalid&nbsp;for&nbsp;some&nbsp;reason,&nbsp;such&nbsp;as&nbsp;ring&nbsp;clockwise&nbsp;etc,&nbsp;it&nbsp;won't&nbsp;throw&nbsp;exception,&nbsp;but&nbsp;SqlTypes&nbsp;won't&nbsp;take&nbsp;it.&nbsp;It&nbsp;throws&nbsp;exceptions&nbsp;directly.&nbsp;So&nbsp;causes&nbsp;the&nbsp;exception&nbsp;you&nbsp;met.&nbsp;  
&nbsp;  
I&nbsp;have&nbsp;two&nbsp;suggestions&nbsp;to&nbsp;workaround&nbsp;it.  
  
&nbsp;  
1,&nbsp;We&nbsp;won't&nbsp;integrate&nbsp;this&nbsp;change&nbsp;into&nbsp;our&nbsp;release&nbsp;branch&nbsp;(version&nbsp;number&nbsp;is&nbsp;like&nbsp;6.0.0.\*)&nbsp;until&nbsp;the&nbsp;next&nbsp;major&nbsp;release.&nbsp;But&nbsp;it&nbsp;has&nbsp;all&nbsp;bug&nbsp;fixed.&nbsp;So&nbsp;it&nbsp;is&nbsp;a&nbsp;stable&nbsp;version&nbsp;to&nbsp;use.&nbsp;Please&nbsp;have&nbsp;a&nbsp;try.  
  
&nbsp;  
2,&nbsp;If&nbsp;the&nbsp;development&nbsp;branch&nbsp;is&nbsp;required&nbsp;in&nbsp;your&nbsp;system,&nbsp;we&nbsp;have&nbsp;two&nbsp;static&nbsp;properties&nbsp;to&nbsp;switch&nbsp;back&nbsp;to&nbsp;our&nbsp;old&nbsp;shape&nbsp;core:&nbsp;NTS.&nbsp;Please&nbsp;copy&nbsp;the&nbsp;following&nbsp;properties&nbsp;to&nbsp;the&nbsp;method&nbsp;when&nbsp;the&nbsp;application&nbsp;starts.&nbsp;For&nbsp;example:  
  
  
`public partial class App : Application{    protected override void OnStartup(StartupEventArgs e)    {        base.OnStartup(e);        Feature.GeometryLibrary = GeometryLibrary.Managed;        BaseShape.GeometryLibrary = GeometryLibrary.Managed;    }}`  
&nbsp;  
"Managed"&nbsp;means&nbsp;the&nbsp;NTS,&nbsp;while&nbsp;"Unmanaged"&nbsp;means&nbsp;SqlTypes.&nbsp;Please&nbsp;try&nbsp;this&nbsp;one.  
&nbsp;  
We&nbsp;will&nbsp;keep&nbsp;testing&nbsp;this&nbsp;new&nbsp;feature&nbsp;and&nbsp;make&nbsp;it&nbsp;stable&nbsp;in&nbsp;the&nbsp;near&nbsp;future.  
&nbsp;  
Thanks,  
Howard
