# Null Exception when using labels

**URL:** <https://community.thinkgeo.com/t/null-exception-when-using-labels/388>\
**Category:** WinForms\
**Created:** [April 24, 2009, 10:15am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388 "2009-04-24T10:15:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@Alan1](https://community.thinkgeo.com/u/Alan1)\
**Post date:** [April 24, 2009, 10:15am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/1 "2009-04-24T10:15:06Z")

</div>

I&nbsp;have&nbsp;been&nbsp;experiencing&nbsp;many&nbsp;"NullRefrence&nbsp;Exceptions&nbsp;not&nbsp;handled"

I&nbsp;have&nbsp;narrowed&nbsp;it&nbsp;down&nbsp;to&nbsp;using&nbsp;labels,&nbsp;It&nbsp;does&nbsp;not&nbsp;seem&nbsp;to&nbsp;matter&nbsp;if&nbsp;I&nbsp;use&nbsp;the&nbsp;built&nbsp;in&nbsp;TextStyles&nbsp;or&nbsp;a&nbsp;custom&nbsp;TextStyle.&nbsp;The&nbsp;errors&nbsp;occur&nbsp;during&nbsp;redraws&nbsp;(Panning,&nbsp;Zoom&nbsp;In,&nbsp;and&nbsp;Zoom&nbsp;Out)&nbsp;.&nbsp;There&nbsp;does&nbsp;not&nbsp;seem&nbsp;to&nbsp;be&nbsp;a&nbsp;common&nbsp;way&nbsp;to&nbsp;duplicate&nbsp;and&nbsp;seem&nbsp;to&nbsp;occur&nbsp;randomly&nbsp;-&nbsp;In&nbsp;other&nbsp;words,&nbsp;If&nbsp;I&nbsp;perform&nbsp;a&nbsp;given&nbsp;zoom&nbsp;and&nbsp;once&nbsp;and&nbsp;receive&nbsp;an&nbsp;error,&nbsp;It&nbsp;may&nbsp;or&nbsp;may&nbsp;not&nbsp;occur&nbsp;again&nbsp;the&nbsp;next&nbsp;time&nbsp;even&nbsp;though&nbsp;I&nbsp;repeat&nbsp;the&nbsp;steps&nbsp;exactly&nbsp;as&nbsp;the&nbsp;first&nbsp;time.

Below&nbsp;is&nbsp;the&nbsp;ouput&nbsp;from&nbsp;the&nbsp;exception.

System.NullReferenceException&nbsp;was&nbsp;unhandled  
  
&nbsp;&nbsp;Message="Object&nbsp;reference&nbsp;not&nbsp;set&nbsp;to&nbsp;an&nbsp;instance&nbsp;of&nbsp;an&nbsp;object."  
  
&nbsp;&nbsp;Source="MapSuiteCore"  
  
&nbsp;&nbsp;StackTrace:  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.x5e8ba87a6e4f7872(PolygonShape&nbsp;xdd1257604b85b26a,&nbsp;String&nbsp;x8d11a5f0a2282818,&nbsp;GeoCanvas&nbsp;x31c084515ae9393f)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.xf2594a7578927384(MultipolygonShape&nbsp;x3ebe6da76843c14a,&nbsp;String&nbsp;x8d11a5f0a2282818,&nbsp;GeoCanvas&nbsp;x31c084515ae9393f)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.xa560424e1568ae1a(MultipolygonShape&nbsp;x3ebe6da76843c14a,&nbsp;String&nbsp;x8d11a5f0a2282818,&nbsp;GeoCanvas&nbsp;x31c084515ae9393f)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.GetLabelingCandidateCore(Feature&nbsp;feature,&nbsp;GeoCanvas&nbsp;canvas)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.GetLabelingCandidates(Feature&nbsp;feature,&nbsp;GeoCanvas&nbsp;canvas)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.xf735974b04b9e074(Feature&nbsp;x79fd310d5eca45f6,&nbsp;GeoCanvas&nbsp;x31c084515ae9393f,&nbsp;Collection`1&nbsp;x00f17d7e921affcc,&nbsp;Collection`1&nbsp;xd03d0815a07e11bc)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.PositionStyle.DrawCore(IEnumerable`1&nbsp;features,&nbsp;GeoCanvas&nbsp;canvas,&nbsp;Collection`1&nbsp;labelsInThisLayer,&nbsp;Collection`1&nbsp;labelsInAllLayers)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.Style.Draw(IEnumerable`1&nbsp;features,&nbsp;GeoCanvas&nbsp;canvas,&nbsp;Collection`1&nbsp;labelsInThisLayer,&nbsp;Collection`1&nbsp;labelsInAllLayers)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.ZoomLevel.DrawCore(GeoCanvas&nbsp;canvas,&nbsp;IEnumerable`1&nbsp;features,&nbsp;Collection`1&nbsp;currentLayerLabels,&nbsp;Collection`1&nbsp;allLayerLabels)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.ZoomLevel.Draw(GeoCanvas&nbsp;canvas,&nbsp;IEnumerable`1&nbsp;features,&nbsp;Collection`1&nbsp;currentLayerLabels,&nbsp;Collection`1&nbsp;allLayerLabels)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas&nbsp;canvas,&nbsp;Collection`1&nbsp;labelsInAllLayers)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas&nbsp;canvas,&nbsp;Collection`1&nbsp;labelsInAllLayers)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.xa6cb874f7090c07f(GeoCanvas&nbsp;x31c084515ae9393f)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas&nbsp;canvas)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas&nbsp;canvas)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.xf0380b1a0bc40ca6.StartDraw()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.x601a5561df898600.StartDraw(Int32&nbsp;tileWidth,&nbsp;Int32&nbsp;tileHeight,&nbsp;RectangleShape&nbsp;tileExtent,&nbsp;Collection`1&nbsp;overlays)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.x601a5561df898600.DrawAddedExtents(IEnumerable`1&nbsp;addedExtents,&nbsp;Collection`1&nbsp;overlays)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.Refresh(x177b8d80e88ce3a2&nbsp;tempRedrawMode)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.DrawNewImage(Int32&nbsp;delayInterval)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.delayDrawingTimer\_Tick(Object&nbsp;sender,&nbsp;EventArgs&nbsp;e)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Timer.OnTick(EventArgs&nbsp;e)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message&&nbsp;m)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr&nbsp;hWnd,&nbsp;Int32&nbsp;msg,&nbsp;IntPtr&nbsp;wparam,&nbsp;IntPtr&nbsp;lparam)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&&nbsp;msg)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32&nbsp;dwComponentID,&nbsp;Int32&nbsp;reason,&nbsp;Int32&nbsp;pvLoopData)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32&nbsp;reason,&nbsp;ApplicationContext&nbsp;context)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32&nbsp;reason,&nbsp;ApplicationContext&nbsp;context)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Windows.Forms.Application.Run(ApplicationContext&nbsp;context)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]&nbsp;commandLine)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;KTrac3.My.MyApplication.Main(String[]&nbsp;Args)&nbsp;in&nbsp;17d14f5c-a337-4978-8281-53493378c1071.vb:line&nbsp;81  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.AppDomain.\_nExecuteAssembly(Assembly&nbsp;assembly,&nbsp;String[]&nbsp;args)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.AppDomain.ExecuteAssembly(String&nbsp;assemblyFile,&nbsp;Evidence&nbsp;assemblySecurity,&nbsp;String[]&nbsp;args)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Threading.ThreadHelper.ThreadStart\_Context(Object&nbsp;state)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Threading.ExecutionContext.Run(ExecutionContext&nbsp;executionContext,&nbsp;ContextCallback&nbsp;callback,&nbsp;Object&nbsp;state)  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Threading.ThreadHelper.ThreadStart()  
  
&nbsp;&nbsp;InnerException:&nbsp;  
  
&nbsp;

---

<div class="post-metadata">

**Author:** ![Alan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@Alan1](https://community.thinkgeo.com/u/Alan1)\
**Post date:** [April 27, 2009, 10:44am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/2 "2009-04-27T10:44:58Z")

</div>

Am&nbsp;I&nbsp;the&nbsp;only&nbsp;one&nbsp;with&nbsp;this&nbsp;problem???

---

<div class="post-metadata">

**Author:** ![Lee](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@Lee](https://community.thinkgeo.com/u/Lee)\
**Post date:** [April 28, 2009, 4:38am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/3 "2009-04-28T04:38:36Z")

</div>

Alan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;We&nbsp;can’t&nbsp;recreate&nbsp;this&nbsp;issue.&nbsp;Could&nbsp;you&nbsp;please&nbsp;tell&nbsp;more&nbsp;about&nbsp;how&nbsp;you&nbsp;setup&nbsp;the&nbsp;style?&nbsp;It’s&nbsp;better&nbsp;if&nbsp;you&nbsp;can&nbsp;provide&nbsp;a&nbsp;demo&nbsp;even&nbsp;if&nbsp;it&nbsp;goes&nbsp;into&nbsp;the&nbsp;issue&nbsp;randomly.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks, &nbsp;  
&nbsp;ThinkGeo&nbsp;Support&nbsp;

---

<div class="post-metadata">

**Author:** ![Alan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@Alan1](https://community.thinkgeo.com/u/Alan1)\
**Post date:** [April 29, 2009, 10:22am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/4 "2009-04-29T10:22:16Z")

</div>

I&nbsp;have&nbsp;narrowed&nbsp;it&nbsp;down&nbsp;to&nbsp;the&nbsp;AllowLineCarriage&nbsp;property&nbsp;in&nbsp;the&nbsp;TextStyle&nbsp;class&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Private&nbsp;Function&nbsp;GetHotelTextStyle(ByVal&nbsp;FieldName&nbsp;As&nbsp;String,&nbsp;Optional&nbsp;ByVal&nbsp;FontSize&nbsp;As&nbsp;Integer&nbsp;=&nbsp;10,&nbsp;Optional&nbsp;ByVal&nbsp;FontName&nbsp;As&nbsp;String&nbsp;=&nbsp;“Arial”)&nbsp;As&nbsp;TextStyle&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim&nbsp;ts&nbsp;As&nbsp;TextStyle&nbsp;=&nbsp;TextStyles.CreateSimpleTextStyle(FieldName,&nbsp;FontName,&nbsp;FontSize,&nbsp;FontStyle.Bold,&nbsp;GeoColor.SimpleColors.Blue,&nbsp;GeoColor.StandardColors.White,&nbsp;2)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ts.OverlappingRule&nbsp;=&nbsp;LabelOverlappingRule.NoOverlapping&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ts.AllowLineCarriage&nbsp;=&nbsp;True&nbsp;'this&nbsp;will&nbsp;ramdomly&nbsp;cause&nbsp;NullReferenceException&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ts.ForceLineCarriage&nbsp;=&nbsp;True&nbsp;'works&nbsp;fine&nbsp;with&nbsp;this.&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ts.HaloPen.LineJoin&nbsp;=&nbsp;DrawingLineJoin.Round&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return&nbsp;ts&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Function

---

<div class="post-metadata">

**Author:** ![Lee](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@Lee](https://community.thinkgeo.com/u/Lee)\
**Post date:** [May 1, 2009, 1:41am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/5 "2009-05-01T01:41:24Z")

</div>

Thanks,&nbsp;we&nbsp;will&nbsp;look&nbsp;into&nbsp;this.&nbsp;  
&nbsp;&nbsp;  
&nbsp;ThinkGeo&nbsp;Support&nbsp;

---

<div class="post-metadata">

**Author:** ![David\_Edwardson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/c6cbf5/32.png) [@David\_Edwardson](https://community.thinkgeo.com/u/David_Edwardson)\
**Post date:** [May 1, 2009, 10:04am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/6 "2009-05-01T10:04:57Z")

</div>

I&nbsp;am&nbsp;also&nbsp;getting&nbsp;this&nbsp;exception&nbsp;occasionally&nbsp;on&nbsp;zooms&nbsp;and&nbsp;also&nbsp;on&nbsp;resize&nbsp;events.

---

<div class="post-metadata">

**Author:** ![Lee](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@Lee](https://community.thinkgeo.com/u/Lee)\
**Post date:** [May 5, 2009, 6:19am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/7 "2009-05-05T06:19:11Z")

</div>

Alan&nbsp;&&nbsp;David,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;still&nbsp;can&nbsp;not&nbsp;recreate&nbsp;this&nbsp;issue&nbsp;using&nbsp;your&nbsp;code.&nbsp;And&nbsp;I&nbsp;noticed&nbsp;that&nbsp;you&nbsp;are&nbsp;not&nbsp;using&nbsp;the&nbsp;current&nbsp;release&nbsp;version&nbsp;(3.0.199)&nbsp;as&nbsp;the&nbsp;4th&nbsp;parameter&nbsp;of&nbsp;method&nbsp;CreateSimpleTextStyle&nbsp;()&nbsp;is&nbsp;DrawingFontStyles&nbsp;in&nbsp;3.0.199.&nbsp;Could&nbsp;you&nbsp;please&nbsp;check&nbsp;your&nbsp;version?&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;can&nbsp;download&nbsp;the&nbsp;latest&nbsp;version&nbsp;from&nbsp;[gis.thinkgeo.com/Products/MapSuiteFreeTrialDownloads/tabid/152/Default.aspx](http://gis.thinkgeo.com/Products/MapSuiteFreeTrialDownloads/tabid/152/Default.aspx)&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;ThinkGeo&nbsp;Support&nbsp;

---

<div class="post-metadata">

**Author:** ![David\_Edwardson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/c6cbf5/32.png) [@David\_Edwardson](https://community.thinkgeo.com/u/David_Edwardson)\
**Post date:** [May 5, 2009, 8:51am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/8 "2009-05-05T08:51:19Z")

</div>

I&nbsp;am&nbsp;using&nbsp;3.0.199.&nbsp;&nbsp;I&nbsp;set&nbsp;'AllowLineCarriage'&nbsp;back&nbsp;to&nbsp;true&nbsp;and&nbsp;the&nbsp;exception&nbsp;occurs&nbsp;when&nbsp;zooming&nbsp;out&nbsp;(sometimes&nbsp;once,&nbsp;sometimes&nbsp;several&nbsp;times...threading???)

Exception:

&nbsp;

`System.NullReferenceException was unhandled  Message="Object reference not set to an instance of an object."  Source="MapSuiteCore"  StackTrace:       at ThinkGeo.MapSuite.Core.PositionStyle.x5e8ba87a6e4f7872(PolygonShape xdd1257604b85b26a, String x8d11a5f0a2282818, GeoCanvas x31c084515ae9393f)       at ThinkGeo.MapSuite.Core.PositionStyle.xa560424e1568ae1a(MultipolygonShape x3ebe6da76843c14a, String x8d11a5f0a2282818, GeoCanvas x31c084515ae9393f)       at ThinkGeo.MapSuite.Core.PositionStyle.GetLabelingCandidateCore(Feature feature, GeoCanvas canvas)       at ThinkGeo.MapSuite.Core.PositionStyle.xf735974b04b9e074(Feature x79fd310d5eca45f6, GeoCanvas x31c084515ae9393f, Collection`1 x00f17d7e921affcc, Collection`1 xd03d0815a07e11bc)       at ThinkGeo.MapSuite.Core.PositionStyle.DrawCore(IEnumerable`1 features, GeoCanvas canvas, Collection`1 labelsInThisLayer, Collection`1 labelsInAllLayers)       at ThinkGeo.MapSuite.Core.Style.Draw(IEnumerable`1 features, GeoCanvas canvas, Collection`1 labelsInThisLayer, Collection`1 labelsInAllLayers)       at ThinkGeo.MapSuite.Core.ZoomLevel.DrawCore(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)       at ThinkGeo.MapSuite.Core.ZoomLevel.Draw(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)       at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)       at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)       at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.xa6cb874f7090c07f(GeoCanvas x31c084515ae9393f)       at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)       at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)       at ThinkGeo.MapSuite.DesktopEdition.xf0380b1a0bc40ca6.StartDraw()       at ThinkGeo.MapSuite.DesktopEdition.x601a5561df898600.StartDraw(Int32 tileWidth, Int32 tileHeight, RectangleShape tileExtent, Collection`1 overlays)       at ThinkGeo.MapSuite.DesktopEdition.x601a5561df898600.DrawAddedExtents(IEnumerable`1 addedExtents, Collection`1 overlays)       at ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.Refresh(x177b8d80e88ce3a2 tempRedrawMode)       at ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.DrawNewImage(Int32 delayInterval)       at ThinkGeo.MapSuite.DesktopEdition.x65fdca92d79c01f5.delayDrawingTimer_Tick(Object sender, EventArgs e)       at System.Windows.Forms.Timer.OnTick(EventArgs e)       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)       at System.Windows.Forms.Application.Run(Form mainForm)       at ActiveMap.Program.Main() in C:\CMS\ActiveMap\Program.cs:line 17       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()`

&nbsp;

TextStyle&nbsp;setup:

`                  if ( zl.Text != null )                  {                     // Text for zoom level is defined                     GeoColor gcolor = GeoColor.FromArgb(zl.Text.Color.A, zl.Text.Color.R,                                          zl.Text.Color.G, zl.Text.Color.B);                     long inverseA, inverseR, inverseG, inverseB;                     Math.DivRem(gcolor.AlphaComponent, 127, out inverseA);                     Math.DivRem(gcolor.BlueComponent, 127, out inverseB);                     Math.DivRem(gcolor.GreenComponent, 127, out inverseG);                     Math.DivRem(gcolor.RedComponent, 127, out inverseR);                     GeoColor outColor = GeoColor.FromArgb((int)inverseA, (int)inverseR,                                                            (int)inverseG, (int)inverseB);                     string textColumn = zl.Text.TextFields; //.Trim(new char [] { '[', ']' });                     TextStyle textStyle = TextStyles.CreateSimpleTextStyle(textColumn,                                             zl.Text.Font.FontFamily.Name, zl.Text.Font.Size,                                             FontStyleToDrawingStyle(zl.Text.Font.Style), gcolor, outColor, 2, 0, -2);                     textStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;                     textStyle.PointPlacement = PointPlacement.UpperRight;                     textStyle.SuppressPartialLabels = true;                     textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;                     textStyle.AllowLineCarriage = true; // according to blog true causes null exceptions on random zooms in Beta                     textStyle.AllowSpline = true;                     textStyle.BestPlacement = true;                     pzl.CustomStyles.Add(textStyle);                  }`

&nbsp;

The&nbsp;enumerations&nbsp;of&nbsp;DrawingFontStyles&nbsp;does&nbsp;not&nbsp;equate&nbsp;to&nbsp;System.Drawing.FontStyle&nbsp;so&nbsp;I&nbsp;added&nbsp;a&nbsp;helper&nbsp;function&nbsp;(below).&nbsp;&nbsp;Same&nbsp;with&nbsp;LineDashStyle&nbsp;to&nbsp;System.Drawing.Drawing2D.DashStyle.

`      private DrawingFontStyles FontStyleToDrawingStyle( FontStyle style )      {         if ( style == FontStyle.Regular )            return DrawingFontStyles.Regular;         else if ( style == FontStyle.Bold )            return DrawingFontStyles.Bold;         else if ( style == FontStyle.Italic )            return DrawingFontStyles.Italic;         else if ( style == FontStyle.Strikeout )            return DrawingFontStyles.Strikeout;         else if ( style == FontStyle.Underline )            return DrawingFontStyles.Underline;         return DrawingFontStyles.Regular;      }`

&nbsp;

---

<div class="post-metadata">

**Author:** ![Alan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@Alan1](https://community.thinkgeo.com/u/Alan1)\
**Post date:** [May 5, 2009, 10:12am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/9 "2009-05-05T10:12:48Z")

</div>

Lee,

Yes,&nbsp;I&nbsp;am&nbsp;usiing&nbsp;3.0.199.&nbsp;Actually&nbsp;I&nbsp;didn't&nbsp;begin&nbsp;testing&nbsp;until&nbsp;you&nbsp;included&nbsp;source&nbsp;for&nbsp;VB&nbsp;in&nbsp;the&nbsp;latest&nbsp;release.&nbsp;I&nbsp;can&nbsp;use&nbsp;either&nbsp;C#&nbsp;or&nbsp;VB,&nbsp;But&nbsp;I&nbsp;prefer&nbsp;VB.

I&nbsp;have&nbsp;been&nbsp;using&nbsp;the&nbsp;ForceLineCarriage&nbsp;instead&nbsp;of&nbsp;AllowLineCarriage&nbsp;because&nbsp;ForceLineCarriage&nbsp;doesn't&nbsp;throw&nbsp;this&nbsp;exception.&nbsp;I&nbsp;have&nbsp;been&nbsp;using&nbsp;this&nbsp;for&nbsp;about&nbsp;a&nbsp;week&nbsp;without&nbsp;errors.

In&nbsp;response&nbsp;to&nbsp;your&nbsp;question&nbsp;I&nbsp;set&nbsp;it&nbsp;back&nbsp;to&nbsp;using&nbsp;AllowLineCarriage&nbsp;and&nbsp;immediately&nbsp;got&nbsp;the&nbsp;same&nbsp;error&nbsp;as&nbsp;before.&nbsp;I&nbsp;also&nbsp;changed&nbsp;the&nbsp;Font&nbsp;Parameter&nbsp;from&nbsp;FontStyle.Bold&nbsp;to&nbsp;DrawingFontStyles.Bold&nbsp;and&nbsp;the&nbsp;error&nbsp;still&nbsp;occurs.

Note&nbsp;that&nbsp;it&nbsp;will&nbsp;accept&nbsp;either&nbsp;FontStyle.Bold&nbsp;or&nbsp;DrawingFontStyles.Bold&nbsp;and&nbsp;still&nbsp;works&nbsp;the&nbsp;same&nbsp;in&nbsp;either&nbsp;scenario.

The&nbsp;only&nbsp;common&nbsp;factor&nbsp;in&nbsp;creating&nbsp;and&nbsp;preventing&nbsp;the&nbsp;error&nbsp;is&nbsp;the&nbsp;AllowLineCarriage.&nbsp;As&nbsp;long&nbsp;as&nbsp;this&nbsp;set&nbsp;to&nbsp;false&nbsp;I&nbsp;can&nbsp;change&nbsp;any&nbsp;of&nbsp;the&nbsp;other&nbsp;properties&nbsp;and&nbsp;not&nbsp;get&nbsp;errors.

Alan

---

<div class="post-metadata">

**Author:** ![Alan1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/a/5e9695/32.png) [@Alan1](https://community.thinkgeo.com/u/Alan1)\
**Post date:** [May 6, 2009, 10:17am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/10 "2009-05-06T10:17:45Z")

</div>

I&nbsp;have&nbsp;attached&nbsp;the&nbsp;shape&nbsp;file&nbsp;used&nbsp;when&nbsp;this&nbsp;error&nbsp;occurs.&nbsp;Hotel.shp

&nbsp;

`        Dim HotelLabelLayer As New ShapeFileFeatureLayer(DataPath & "Hotel.shp")        With HotelLabelLayer.ZoomLevelSet            .ZoomLevel15.CustomStyles.Add(GetHotelTextStyle("FAC_NAME"))            .ZoomLevel15.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20            Map1.StaticOverlay.Layers.Add("HotelLabel", HotelLabelLayer)        End With`

&nbsp;

`   Private Function GetHotelTextStyle(ByVal FieldName As String, Optional ByVal FontSize As Integer = 10, Optional ByVal FontName As String = "Arial") As TextStyle        Dim HotelTextStyle As TextStyle = TextStyles.CreateSimpleTextStyle(FieldName, FontName, FontSize, DrawingFontStyles.Bold, GeoColor.SimpleColors.Blue, GeoColor.StandardColors.White, 2)        HotelTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping        'HotelTextStyle.ForceLineCarriage = True 'works without errors        HotelTextStyle.AllowLineCarriage = True 'randomly throws exception during changes in zoom        HotelTextStyle.HaloPen.LineJoin = DrawingLineJoin.Round        Return HotelTextStyle    End Function`  
  
[659-Hotel.zip](https://community.thinkgeo.com/uploads/default/original/2X/c/cd66a903a0543f29a4f0a9a9a15c136d01f9be3f.zip) (180 KB)

---

<div class="post-metadata">

**Author:** ![Lee](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@Lee](https://community.thinkgeo.com/u/Lee)\
**Post date:** [May 8, 2009, 2:50am UTC](https://community.thinkgeo.com/t/null-exception-when-using-labels/388/11 "2009-05-08T02:50:01Z")

</div>

Thanks&nbsp;Alan,&nbsp;  
&nbsp;&nbsp;  
&nbsp;This&nbsp;is&nbsp;a&nbsp;bug&nbsp;and&nbsp;we&nbsp;will&nbsp;fix&nbsp;it&nbsp;in&nbsp;next&nbsp;version.&nbsp;Sorry&nbsp;for&nbsp;the&nbsp;inconvenience&nbsp;for&nbsp;now.&nbsp;  
&nbsp;&nbsp;  
&nbsp;ThinkGeo&nbsp;Support&nbsp;
