Here's my piece of code:
' file is a .shp-file
Dim fs As FeatureSet = CType(FeatureSet.Open(file.FullName), FeatureSet)
Dim layer As New MapPolygonLayer(fs)
Dim scheme As New DotSpatial.Symbology.PolygonScheme()
Dim fillColor As Color
Dim outlineColor As Color
for each area in areaXML ' This will be looped 3 times
fillColor = ColorTranslator.FromHtml("#" & area.ForegroundColor)
outlineColor = ColorTranslator.FromHtml("#" & area.Color)
Dim category As New DotSpatial.Symbology.PolygonCategory(fillColor, outlineColor, 1)
category.FilterExpression = area.Filter.ToString()
scheme.AddCategory(category)
Next
layer.Symbology = scheme ' Exception will be thrown here! Message: Index was outside the bounds of the array.
Stacktrace:
at DotSpatial.Symbology.FeatureLayer.AssignFastDrawnStates()
at DotSpatial.Symbology.FeatureLayer.OnApplyScheme(IFeatureScheme scheme)
at DotSpatial.Symbology.FeatureLayer.ApplyScheme(IFeatureScheme inScheme)
at DotSpatial.Symbology.FeatureLayer.set_Symbology(IFeatureScheme value)
at DotSpatial.Symbology.PolygonLayer.set_Symbology(IPolygonScheme value)
at VitecDotSpatial.MainForm.ReadLayers() in C:\Src\Energy\NIS\VitecDotSpatial\VitecDotSpatial\MainForm.vb:line 1117
This part of the code works most of the time, but sometimes so does it throw an exception like above. And I don't understand why.