ThinkGeo.com    |     Blog    |     Wiki    |     Support

The FeatureSource is not open bug

Hi,
I am facing lots of issues about this bug.
‘The FeatureSource is not open. Please call the Open method before calling this method.’

Whenever using any feature source methods, i am making layer open and also feature source open.
Even though, some of the times it’s raising this bug. I debug it clearly, in some of the times if we execute layer.featuresource.open() method then layer is opened but feature source is not opened. i think that’s why only it’s raising this bug.

I am not sure when it’s happening because if we check one more time on that time, layer and feature source both are opened by calling open method.

Can you clearly explain me, How to handle this bug.
Mostly i am using InMemoryFeatureLayer and ShapeFileFeatureLayer feature source methods.

Code:
1.
ShapeFileFeatureLayer _shpATSPoints = new ShapeFileFeatureLayer(“path\Shape.shp”);
if (!_shpATSPoints.IsOpen)
_shpATSPoints.Open();
_shpATSPoints.FeatureSource.Open();
List features = _shpATSPoints.FeatureSource.SpatialQuery().ToList();
_shpATSPoints.FeatureSource.Close();
_shpATSPoints.Close();
2.
InMemoryFeatureLayer imAircraftLayer = (InMemoryFeatureLayer)((LayerOverlay)wfMap.CustomOverlays[“AircraftOverlay”]).Layers[“Layer1”];
if (!imAircraftLayer.IsOpen)
imAircraftLayer.Open();
imAircraftLayer.FeatureSource.Open();
fts_SelectedAircrafts = imAircraftLayer.FeatureSource.GetFeaturesWithinDistanceOf(e.Position, wfMap.MapUnit, DistanceUnit.NauticalMile, _dAircraftMouseClickDistance, ReturningColumnsType.AllColumns).ToList();
imAircraftLayer.FeatureSource.Close();
imAircraftLayer.Close();

Note: is layer needs to lock then only we can use it.

Thanks,
Riyaz

Hi Riyaz,

The layer.open in fact call the featuresource.open, so you don’t need to open it again.

And if you don’t need to remove this layer immediately, I think you don’t need to close it, you can keep it’s open till it will be removed from map.

If you still think it’s a problem, a sample for reproduce it is welcome, because we hadn’t reproduced this exception by your sample code.

Regards,

Ethan

Hi,
I am keep on facing this issue, even though i have opened both layer and feature source, i am still getting the ‘feature source not open’ error.
My code is inside the looping, i have tried opening feature source above the looping and inside the looping.

But still facing this issue. Please help me in solving this issue.

Note : I can’t make sample for it.

Thanks,
Riyaz

Hi Riyaz,

You mentioned the class you are using is “InMemoryFeatureLayer and ShapeFileFeatureLayer”, they are the basic layer of our product, and it’s stable, so generally if you don’t have custom override of them, it should works well. For us it’s hard to reproduce the exception based on current information.

So we want to make sure:

  1. Your detail package versions, or you can try to use latest version of our release or development package to reproduce it and let us know.

  2. Have you tried my suggestion to don’t call close function and see whether it can be reproduced.

  3. Please let us know whether you call any other API for the layers, or even you only render the layer it will throw the exception.

Any other information please let us know.

Regards,

Ethan

Hi Ethan,
1. Thinkgeo web edition 10.2.9.0 Version
2. We removed every close methods. Now we are not using it.
3. We are not call any other API for layers, we are using only Thinkgeo web edition dll’s.

One more thing, I noticed even if we call layer.open() and layer.featuresource.open(), some times it’s not open the layer.
I don’t know what actually problem, but the methods are failing sometimes, for that layer not opened then this bug is coming.

Can you please suggest me any other solution for it in ASAP.

Thanks,
Riyaz

Hi Riyaz,

Our shape file and inmemory feature layer don’t support multi-thread operation well, so if you have “write” operation, please lock the object or avoid to use it in multi-thread scenario.

I am not sure whether you only “read” the shape file, and whether your code run under multi-thread(or multi-user). If so please make sure call “open” in each thread, it can make sure the layer won’t be used before it opened.

And our developer want to know how you get the exception, we need to know which layers you are using, and what the steps before you met the exception, some call stack maybe helpful.

Regards,

Ethan