# GenerateGrid exception

**URL:** <https://community.thinkgeo.com/t/generategrid-exception/2605>\
**Category:** WinForms\
**Created:** [September 8, 2015, 10:09am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605 "2015-09-08T10:09:43Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Scott5](https://community.thinkgeo.com/u/Scott5)\
**Post date:** [September 8, 2015, 10:09am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/1 "2015-09-08T10:09:43Z")

</div>

Hello&nbsp;Forum,  
  
  
  
We’re&nbsp;generating&nbsp;some&nbsp;colour&nbsp;layers&nbsp;using&nbsp;GridFeatureLayer&nbsp;(similar&nbsp;to&nbsp;those&nbsp;used&nbsp;in&nbsp;your&nbsp;"Isolines&nbsp;With&nbsp;Kriging"&nbsp;code&nbsp;sample).&nbsp;To&nbsp;do&nbsp;this&nbsp;we&nbsp;need&nbsp;to&nbsp;call&nbsp;the&nbsp;static&nbsp;GridFeatureSource.GenerateGrid&nbsp;method&nbsp;using&nbsp;an&nbsp;appropriate&nbsp;interpolation&nbsp;model.&nbsp;We&nbsp;use&nbsp;a&nbsp;LinealKrigingGridInterpolationModel&nbsp;with&nbsp;5&nbsp;reference&nbsp;points&nbsp;(Desktop&nbsp;Edition&nbsp;9).  
  
  
  
Our&nbsp;data&nbsp;points&nbsp;are&nbsp;a&nbsp;scattering&nbsp;of&nbsp;values&nbsp;arranged&nbsp;basically&nbsp;in&nbsp;a&nbsp;grid&nbsp;formation&nbsp;but&nbsp;with&nbsp;patches&nbsp;often&nbsp;missing,&nbsp;and&nbsp;it&nbsp;generally&nbsp;causes&nbsp;no&nbsp;problems&nbsp;when&nbsp;generating&nbsp;the&nbsp;grid.&nbsp;However,&nbsp;on&nbsp;occasion,&nbsp;the&nbsp;method&nbsp;fails&nbsp;and&nbsp;does&nbsp;so&nbsp;in&nbsp;a&nbsp;manner&nbsp;from&nbsp;which&nbsp;we&nbsp;cannot&nbsp;seem&nbsp;to&nbsp;recover.&nbsp;In&nbsp;the&nbsp;debugger,&nbsp;we&nbsp;receive&nbsp;the&nbsp;following&nbsp;message:  
  
`System.InvalidOperationException was unhandledMessage: An unhandled exception of type ‘System.InvalidOperationException’ occurred in MapSuiteCore.dllAdditional information: The matrix cannot be inversed, please check if the input data is valid. For example 2 points with different values should not have the same coordination.`  
  
  
That’s&nbsp;fine&nbsp;and&nbsp;all,&nbsp;but&nbsp;the&nbsp;exception&nbsp;cannot&nbsp;be&nbsp;caught&nbsp;on&nbsp;our&nbsp;side,&nbsp;it&nbsp;seems,&nbsp;and&nbsp;instead&nbsp;brings&nbsp;down&nbsp;our&nbsp;service.&nbsp;We’d&nbsp;much&nbsp;rather&nbsp;skip&nbsp;the&nbsp;calculation&nbsp;and&nbsp;carry&nbsp;on.&nbsp;I’ll&nbsp;append&nbsp;the&nbsp;stacktrace&nbsp;below,&nbsp;as&nbsp;well&nbsp;as&nbsp;attach&nbsp;an&nbsp;x,y,z&nbsp;data&nbsp;set&nbsp;(in&nbsp;metre&nbsp;map&nbsp;units)&nbsp;which&nbsp;causes&nbsp;the&nbsp;issue&nbsp;for&nbsp;us&nbsp;when&nbsp;we&nbsp;try&nbsp;to&nbsp;generate&nbsp;a&nbsp;grid&nbsp;with&nbsp;100&nbsp;cells&nbsp;along&nbsp;the&nbsp;shortest&nbsp;side.  
  
  
  
Are&nbsp;there&nbsp;any&nbsp;app&nbsp;domain&nbsp;considerations&nbsp;we&nbsp;should&nbsp;be&nbsp;making&nbsp;here&nbsp;which&nbsp;might&nbsp;prevent&nbsp;the&nbsp;exception&nbsp;from&nbsp;propagating&nbsp;from&nbsp;the&nbsp;ThinkGeo&nbsp;code?&nbsp;If&nbsp;you&nbsp;have&nbsp;any&nbsp;ideas&nbsp;on&nbsp;how&nbsp;we&nbsp;can&nbsp;get&nbsp;around&nbsp;this&nbsp;issue,&nbsp;I’d&nbsp;very&nbsp;much&nbsp;appreciate&nbsp;it.  
  
  
  
Many&nbsp;thanks,  
  
Scott&nbsp;D.  
  
---------  
`>	MapSuiteCore.dll!ThinkGeo.MapSuite.Core.KrigingGridInterpolationModel.ahw=(int nPn, double x, double y)	Unknown 	MapSuiteCore.dll!ThinkGeo.MapSuite.Core.KrigingGridInterpolationModel.InterpolateCore(ThinkGeo.MapSuite.Core.RectangleShape cellExtent, ThinkGeo.MapSuite.Core.GridDefinition gridDefinition)	Unknown 	MapSuiteCore.dll!ThinkGeo.MapSuite.Core.GridInterpolationModel.Interpolate(ThinkGeo.MapSuite.Core.RectangleShape cellExtent, ThinkGeo.MapSuite.Core.GridDefinition gridDefinition)	Unknown 	MapSuiteCore.dll!xRM=.Cjc=.DDc=(object objStateInfo)	Unknown 	mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state)	Unknown 	mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown 	mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)	Unknown 	mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()	Unknown 	mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()	Unknown 	mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()	Unknown`  
  
  
  
  
  
  
[001\_data.txt](https://community.thinkgeo.com/uploads/default/original/1X/e0c426dfa56f85efecdb46de305ba393bfdfdc3d.txt) (16.4 KB)

---

<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:** [September 9, 2015, 5:28am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/2 "2015-09-09T05:28:40Z")

</div>

Hi&nbsp;Scott,&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;you&nbsp;visit&nbsp;our&nbsp;sample&nbsp;data&nbsp;in&nbsp;IsoLinesWithKriging&nbsp;sample,&nbsp;you&nbsp;can&nbsp;see&nbsp;the&nbsp;data&nbsp;is&nbsp;splited&nbsp;by&nbsp;“,”&nbsp;and&nbsp;in&nbsp;the&nbsp;project&nbsp;code&nbsp;please&nbsp;visit&nbsp;the&nbsp;function&nbsp;GetWellDepthPointDataFromCSV,&nbsp;it&nbsp;contains&nbsp;a&nbsp;line:&nbsp;string[]&nbsp;parts&nbsp;=&nbsp;line.Split(’,’);&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;can&nbsp;modify&nbsp;it&nbsp;for&nbsp;your&nbsp;data&nbsp;or&nbsp;modify&nbsp;your&nbsp;data&nbsp;to&nbsp;separated&nbsp;by&nbsp;“,”.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;tried&nbsp;to&nbsp;modify&nbsp;the&nbsp;data&nbsp;to&nbsp;separated&nbsp;by&nbsp;“,”&nbsp;and&nbsp;hadn’t&nbsp;met&nbsp;the&nbsp;exception&nbsp;you&nbsp;mentioned.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don

---

<div class="post-metadata">

**Author:** ![Scott5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Scott5](https://community.thinkgeo.com/u/Scott5)\
**Post date:** [September 9, 2015, 10:56am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/3 "2015-09-09T10:56:18Z")

</div>

Thanks&nbsp;for&nbsp;the&nbsp;reply.  
  
  
  
The&nbsp;format&nbsp;of&nbsp;the&nbsp;data&nbsp;file&nbsp;is&nbsp;not&nbsp;relevant&nbsp;here,&nbsp;our&nbsp;application&nbsp;doesn’t&nbsp;actually&nbsp;read&nbsp;it&nbsp;in&nbsp;that&nbsp;way.  
  
  
  
I&nbsp;have&nbsp;modified&nbsp;your&nbsp;Kriging&nbsp;sample&nbsp;application&nbsp;to&nbsp;reproduce&nbsp;the&nbsp;error&nbsp;and&nbsp;have&nbsp;attached&nbsp;it&nbsp;here.&nbsp;It&nbsp;just&nbsp;needed&nbsp;to&nbsp;account&nbsp;for&nbsp;the&nbsp;difference&nbsp;in&nbsp;projection&nbsp;when&nbsp;reading&nbsp;the&nbsp;data&nbsp;file,&nbsp;and&nbsp;to&nbsp;put&nbsp;a&nbsp;try/catch&nbsp;block&nbsp;around&nbsp;the&nbsp;GenerateGrid&nbsp;call.&nbsp;If&nbsp;you&nbsp;start&nbsp;the&nbsp;application&nbsp;and&nbsp;change&nbsp;the&nbsp;number&nbsp;of&nbsp;reference&nbsp;points&nbsp;to&nbsp;4,&nbsp;the&nbsp;exception&nbsp;occurs&nbsp;as&nbsp;described&nbsp;above.&nbsp;This&nbsp;is&nbsp;what&nbsp;is&nbsp;happening&nbsp;for&nbsp;us&nbsp;under&nbsp;various&nbsp;conditions.  
  
  
  
As&nbsp;I&nbsp;mentioned&nbsp;in&nbsp;my&nbsp;original&nbsp;post,&nbsp;while&nbsp;the&nbsp;exception&nbsp;is&nbsp;in&nbsp;itself&nbsp;a&nbsp;problem,&nbsp;the&nbsp;bigger&nbsp;issue&nbsp;is&nbsp;that&nbsp;the&nbsp;entire&nbsp;application&nbsp;crashes&nbsp;when&nbsp;the&nbsp;exception&nbsp;is&nbsp;raised&nbsp;down&nbsp;in&nbsp;the&nbsp;MapSuiteCore.&nbsp;We&nbsp;would&nbsp;like&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;recover&nbsp;from&nbsp;the&nbsp;problem.  
  
  
  
If&nbsp;you&nbsp;have&nbsp;any&nbsp;advice,&nbsp;we&nbsp;would&nbsp;be&nbsp;most&nbsp;grateful.  
  
  
  
Regards,  
  
Scott&nbsp;D.

 ![](https://community.thinkgeo.com/uploads/default/original/2X/3/3116cff40c182d4302d7915e26f634318eb67674.png)  
  
  
  
  
[001\_IsoLinesWithKriging.zip](https://community.thinkgeo.com/uploads/default/original/2X/5/5ef695cf3f1d1037d041fad8e04b2d62c1f9d0b9.zip) (142 KB)

---

<div class="post-metadata">

**Author:** ![Troy](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Troy](https://community.thinkgeo.com/u/Troy)\
**Post date:** [September 10, 2015, 4:21am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/4 "2015-09-10T04:21:09Z")

</div>

Hi&nbsp;Scott,  
  
  
  
Thanks&nbsp;for&nbsp;the&nbsp;sample,&nbsp;it&nbsp;is&nbsp;very&nbsp;easy&nbsp;for&nbsp;us&nbsp;to&nbsp;recreate&nbsp;the&nbsp;issue.&nbsp;Currently,&nbsp;we&nbsp;are&nbsp;working&nbsp;on&nbsp;it&nbsp;and&nbsp;will&nbsp;give&nbsp;you&nbsp;a&nbsp;response&nbsp;asap.  
  
  
  
Thanks,  
  
Troy

---

<div class="post-metadata">

**Author:** ![Scott5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Scott5](https://community.thinkgeo.com/u/Scott5)\
**Post date:** [September 14, 2015, 11:04am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/5 "2015-09-14T11:04:43Z")

</div>

Hello&nbsp;again,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Just&nbsp;wondering&nbsp;if&nbsp;there&nbsp;is&nbsp;any&nbsp;news&nbsp;on&nbsp;this,&nbsp;either&nbsp;a&nbsp;fix&nbsp;or&nbsp;a&nbsp;work-around?&nbsp;Any&nbsp;information&nbsp;much&nbsp;appreciated.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Scott&nbsp;D.

---

<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:** [September 15, 2015, 4:34am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/6 "2015-09-15T04:34:54Z")

</div>

Hi&nbsp;Scott,&nbsp;  
&nbsp;&nbsp;  
&nbsp;That&nbsp;crash&nbsp;caused&nbsp;by&nbsp;exception&nbsp;is&nbsp;thrown&nbsp;in&nbsp;child&nbsp;thread,&nbsp;for&nbsp;now&nbsp;we&nbsp;cannot&nbsp;fix&nbsp;that&nbsp;in&nbsp;our&nbsp;end,&nbsp;as&nbsp;below&nbsp;is&nbsp;a&nbsp;workaround,&nbsp;please&nbsp;let&nbsp;us&nbsp;know&nbsp;whether&nbsp;that&nbsp;can&nbsp;work&nbsp;for&nbsp;you.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;think&nbsp;you&nbsp;can&nbsp;solve&nbsp;that&nbsp;like&nbsp;this:&nbsp;  
&nbsp;&nbsp;  
&nbsp;` public class MyLinealKrigingGridInterpolationModel : LinealKrigingGridInterpolationModel{    double noDataValue = -9999; // You can modify this value equal the value in function CreateGridFile of sample.cs    public MyLinealKrigingGridInterpolationModel()        : base(new Dictionary<PointShape, double>(), 5)    { }    public MyLinealKrigingGridInterpolationModel(IDictionary<PointShape, double> points)        : base(points, 5)    { }    public MyLinealKrigingGridInterpolationModel(IDictionary<PointShape, double> points, int numberOfRefreancedPoints)        : base(points, numberOfRefreancedPoints)    { }    protected override double InterpolateCore(RectangleShape cellExtent, GridDefinition gridDefinition)    {        double result;        try        {            result = base.InterpolateCore(cellExtent, gridDefinition);        }        catch (Exception)        {            result = noDataValue;        }        return result;    }}`&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;use&nbsp;the&nbsp;new&nbsp;class:&nbsp;interpolationModel&nbsp;=&nbsp;new&nbsp;MyLinealKrigingGridInterpolationModel(wellDepthPointData,&nbsp;referencingPointCount);&nbsp;  
&nbsp;&nbsp;  
&nbsp;That&nbsp;will&nbsp;solve&nbsp;your&nbsp;issue.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Don

---

<div class="post-metadata">

**Author:** ![Scott5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Scott5](https://community.thinkgeo.com/u/Scott5)\
**Post date:** [September 15, 2015, 10:50am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/7 "2015-09-15T10:50:20Z")

</div>

Thank&nbsp;you&nbsp;for&nbsp;the&nbsp;response,&nbsp;much&nbsp;appreciated.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;will&nbsp;give&nbsp;this&nbsp;a&nbsp;try&nbsp;now.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Scott&nbsp;D.

---

<div class="post-metadata">

**Author:** ![Troy](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Troy](https://community.thinkgeo.com/u/Troy)\
**Post date:** [September 15, 2015, 8:41pm UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/8 "2015-09-15T20:41:04Z")

</div>

Scott,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Please&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;the&nbsp;issue&nbsp;still&nbsp;persists.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Troy

---

<div class="post-metadata">

**Author:** ![Scott5](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/e480ec/32.png) [@Scott5](https://community.thinkgeo.com/u/Scott5)\
**Post date:** [September 16, 2015, 6:47am UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/9 "2015-09-16T06:47:36Z")

</div>

That&nbsp;fixed&nbsp;the&nbsp;problem,&nbsp;and&nbsp;didn’t&nbsp;stop&nbsp;us&nbsp;generating&nbsp;the&nbsp;contours&nbsp;either.&nbsp;This&nbsp;is&nbsp;great&nbsp;news.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;again&nbsp;for&nbsp;the&nbsp;assistance.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;Scott&nbsp;D.

---

<div class="post-metadata">

**Author:** ![Troy](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Troy](https://community.thinkgeo.com/u/Troy)\
**Post date:** [September 16, 2015, 8:17pm UTC](https://community.thinkgeo.com/t/generategrid-exception/2605/10 "2015-09-16T20:17:09Z")

</div>

Great&nbsp;to&nbsp;hear&nbsp;Don’t&nbsp;suggestion&nbsp;works.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;Troy
