ThinkGeo.com    |     Documentation    |     Premium Support

NullReferenceException specific to ShapeFileFeatureLayer and two maps

Hello,


I came across an odd issue when adding two ShapeFileFeatureLayers to two seperate maps on the same form. The issue is specific to ValueStyles. I have prepared a demo, but essentially I generate a NullReferenceException on map2.refresh when ValueStyle is used on the ShapeFileFeatureLayer. Using a regular AreaStyle allows the draw to occur normally.


The demo is wired to hit "C:\Program Files\ThinkGeo\Map Suite Desktop Full Edition 3.0\Samples\SampleData\Data\Countries02.shp" and ValueStyle off of "LANDLOCKED".


Please let me know your thoughts.


Thanks,


Nelson


 



1745-ValueStyle_and_Second_Map_Test.vbproj.zip (95.8 KB)

Nelson,


Thanks for your post and demo that make me understand much more easily.
 
I can run this sample correctly in my environment (Win7 32 bit), this seems wield. I reviewed the code you provided, and I suggested you when you create the second layer, try not use the clone deep, because the Serialization of the whole object is still under testing. Try to change the following code snippet to see it works:

'Dim layer2 As ShapeFileFeatureLayer = layer1.CloneDeep
Dim layer2 As New ShapeFileFeatureLayer("C:\Program Files\ThinkGeo\Map Suite Desktop Full Edition 3.0\Samples\SampleData\Data\Countries02.shp")
layer2.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(vs)
layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Yale, 
  
 Using the code as you have used above does work. This is ok for the demo, but in my application the CloneDeep has been working for a year now and it has saved me a lot of redundant coding. I am thinking of possibly setting up a Vista machine today (we don’t have any Windows 7 copies available) to try and determine if somehow there is a difference between XP and Vista.  
  
 It seems like the problem only applies to ShapeFileFeatureLayer. If I use WfsFeatureLayer.CloneDeep it works correctly. Is there any way we can work together to get this issue resolved? Any information I can provide of use? The CloneDeep feature is invaluable to me and noone has ever indicated it was experimental at any other time I mentioned it? 
  
 Thanks, 
 Nelson

 


Nelson,
 
I have tested your sample and found the problem is caused by Encoding of ShapeFileFeatureLayer.
 
Encoding is very special that it can not be serialized, we use serialize method to implement CloneDeep. So when you CloneDeep a shape file layer, everything is copy to the new instance, only Encoding not, it will be null after you clone. You need to set Encoding again by yourself.
 
That's our fault in the source code, before we fix this problem, you can use following way to solve the problem.
        Dim layer2 As ShapeFileFeatureLayer = layer1.CloneDeep
        layer2.Encoding = System.Text.Encoding.Default
 
Thanks
James

That seems to do the trick. Thanks both of you!

Nelson, 
  
 We are glad that it’s working with you. 
  
 I also put this bug to our Issue Tracking system, we’re going to keep working on this, when we found the solution and fix it, I will let you know. 
  
 Thanks 
  
 James