ThinkGeo.com    |     Documentation    |     Premium Support

Unable to cast object of type 'ThinkGeo.MapSuite.Core.MsSql2008FeatureLayer' to type 'ThinkGeo.MapSuite.Core.InMemoryFeatureLayer'

My Controller Code is as below: 



 <MapActionFilter()> _
    Function EditShape(map As Map, args As GeoCollection(Of Object)) As String
        Dim dynamicOverlay As LayerOverlay = map.CustomOverlays(“DynamicOverlay”)
        Dim shapeLayer As InMemoryFeatureLayer = dynamicOverlay.Layers(“sql2008Layer”)



        Dim featureJson As String = MapHelper.ConvertFeaturesToJson(shapeLayer.InternalFeatures)
        shapeLayer.InternalFeatures.Clear()
        Return featureJson
    End Function



In .vbHTML File:



<img class=“imgBtn” src="@Url.Content("~/Content/images/btn_edit.png")" id=“buttonEditShape” onclick=“editShape();” alt=“Edit Shape” />



 function editShape() {
        Map1.ajaxCallAction(’@ViewContext.RouteData.Values(“Controller”).ToString()’, “EditShape”, null, editShapeCallback);
    }



    function editShapeCallback(result) {
        var features = Map1.getFeaturesFromJson(result.get_responseData());



        var editOverlay = Map1.getEditOverlay();
        editOverlay.addFeatures(features);



        Map1.getDynamicOverlay().redraw(true);
        Map1.setDrawMode(“Modify”);
    }



When I run it Show me Error:



“Unable to cast object of type ‘ThinkGeo.MapSuite.Core.MsSql2008FeatureLayer’ to type ‘ThinkGeo.MapSuite.Core.InMemoryFeatureLayer’.”


Hi Yogesh, 
  
 The possible problem should be in the code as following: 
   Dim shapeLayer As InMemoryFeatureLayer = dynamicOverlay.Layers(“sql2008Layer”) 
  
 I guess the specific layer “sql2008Layer” added to the “map.CustomOverlays(“DynamicOverlay”)” is not a InMemoryFeatureLayer, it’s should be SQLServer2008FeatureLayer, can you check if you give the correct layer id here?  
  
 Thanks, 
 Johnny