ThinkGeo.com    |     Documentation    |     Premium Support

Unhandled exception displaying .mdb on map

I’m trying to load tables from a .mdb file. The layers are created, added to an overlay which is added to the map. The error appears in ThinkGeo’s FeatureSource.cs class at line 3063 in the function GetFeaturesForDrawingCore:

return this.GetFeaturesInsideBoundingBoxCore(boundingBox, returningColumnNames);

The error is:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.

I’ve tried multiple .mdb files and the same issue happens. No errors are thrown from my code.
The error will not get thrown if my map’s extent doesn’t contain the layer.

Please check my ticket: “Error loading .mdb file” for the .mdb file. I know the ContactPy and ContactLn tables don’t work, but try loading any other table like ContactPt. They all throw the same error.

Hi Dan,

I tested it but it looks your data works well.

Please try attached sample and modify it for reproduce your issue, please don’t forget put your Portsmouth_2000.mdb file into the AppData folder.
9297.zip (11.8 KB)

Regards,

Ethan

Hi, wanted to give an update on this, because I’m still getting an error. Here’s the info I found stepping through ThinkGeo’s code:

First it hits FeatureSource.cs - line 3063:

return this.GetFeaturesInsideBoundingBoxCore(boundingBox, returningColumnNames);

Then GeoFdoFeatureSource.cs - line 367:

((IDisposable) reader).Dispose();

Finally this throws the main error:
FdoVectorFeatureSource.cs - line 246

DataTable dataTable = (DataTable) this.assemblyType.GetMethod("GetFeatures", new Type[2]
      {
        typeof (string),
        typeof (IEnumerable<string>)
      }).Invoke(this.loadObject, new object[2]
      {
        (object) filterString,
        (object) returningColumnNames
      });

The output window displays the following when the error occurs:

in function: private Collection<Feature> FEg\u003D(string filterString, IEnumerable<string> returningColumnNames)
   at MapSuiteFdoExtension.GeoFdoFeatureSource.GetFeatures(String filterString, IEnumerable`1 returningColumnNames) in GeoFdoFeatureSource.cs:line 335</StackTrace><ExceptionString>OSGeo.FDO.Common.Exception: Item 'label' not found in collection 
   at OSGeo.FDO.Schema.PropertyDefinitionCollection.get_Item(String name)
   at MapSuiteFdoExtension.GeoFdoFeatureSource.GetFeatures(String filterString, IEnumerable`1 returningColumnNames) in GeoFdoFeatureSource.cs:line 335</ExceptionString></InnerException></Exception></TraceRecord>
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

I’m about to do the following with the layer:

personalGeoDatabaseFeatureLayer.Open();
personalGeoDatabaseFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
Collection<FeatureSourceColumn> columnNames = personalGeoDatabaseFeatureLayer.FeatureSource.GetColumns();
personalGeoDatabaseFeatureLayer.Close();

And I can confirm from the above that the correct features are in the layer.
The error only happens when I am panning/zooming to an extent that contains any part of the layer.

Converting the .mdb to a filegeodatabase or shapefiles lets me load it in fine. I’m at a loss as to what the error could be.

Hi Dan,

Thanks for your update, it looks your exception is thrown by reflect related code.

I modify some code of my sample but still hadn’t met the same problem, could you please modify it to help us reproduce that?

        private void Form1_Load(object sender, EventArgs e)
    {
        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

        var path = @"..\..\AppData\Portsmouth_2000.mdb";
        PersonalGeoDatabaseFeatureLayer personalGeoDatabaseFeatureLayer = new PersonalGeoDatabaseFeatureLayer(path, "FeatGUID", null, "ContactPt");
        personalGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Green);
        personalGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(100, GeoColor.SimpleColors.Green), 2, true);
        personalGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Triangle, GeoColor.SimpleColors.Red, 10);
        personalGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        var layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(personalGeoDatabaseFeatureLayer);
        winformsMap1.Overlays.Add(layerOverlay);

        personalGeoDatabaseFeatureLayer.Open();
        winformsMap1.CurrentExtent = personalGeoDatabaseFeatureLayer.GetBoundingBox();

        winformsMap1.CurrentExtentChanged += WinformsMap1_CurrentExtentChanged;
        winformsMap1.Refresh();
    }

    private void WinformsMap1_CurrentExtentChanged(object sender, CurrentExtentChangedWinformsMapEventArgs e)
    {
        PersonalGeoDatabaseFeatureLayer personalGeoDatabaseFeatureLayer = (winformsMap1.Overlays[0] as LayerOverlay).Layers[0] as PersonalGeoDatabaseFeatureLayer;

        personalGeoDatabaseFeatureLayer.Open();
        personalGeoDatabaseFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
        Collection<FeatureSourceColumn> columnNames = personalGeoDatabaseFeatureLayer.FeatureSource.GetColumns();
        personalGeoDatabaseFeatureLayer.Close();
    }

Regards,

Ethan

I’ll try to provide the related code:

LayerOverlay mdbOverlay = new LayerOverlay() { Name = "MDB Overlay" }; //create overlay for mdb layers
Map.MapUnit = GeographyUnit.Meter; //set to meters
Map.Overlays.Add("MDB Overlay", MapModel.mdbOverlay); //add overlay to the map

PersonalGeoDatabaseFeatureLayer personalGeoDatabaseFeatureLayer = new PersonalGeoDatabaseFeatureLayer(filePath, "FeatGUID", null, "ContactPt"); //create new layer

personalGeoDatabaseFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleSquareStyle(GeoColors.Red, 10); //set up a default point style

Proj4Projection proj4Projection = new Proj4Projection //since map is in meters, change the layer's external projection
{
    InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326),
    ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3857)
};
personalGeoDatabaseFeatureLayer.FeatureSource.Projection = proj4Projection;

mdbOverlay.Layers.Add("ContactPt", personalGeoDatabaseFeatureLayer); //add layer to correct overlay

Update: Figured out the problem. You might want to let your developers know about this.

I have InMemoryFeatureLayers that I create, as well as features, that have columns named “label”.
The .mdb tables I load in have a column called “Label”.

Whenever those layers/features were in the same extent as the .mdb layer, it would throw that error saying column “label” couldn’t be found deep in ThinkGeo’s code. I’m guessing it’s getting every column name from all layers/features in the current extent instead of treating them separately.

I renamed all my “label” columns to “Label” and now it works properly.

Hi Dan,

I check your exception information and found the “Item ‘label’ not found in collection” it mentioned, we ignore it.

Thanks for your update, it looks the MDB is case sensitive, it should be a helpful point for other guys met the same issue.

I will let our developer know it and I think they will check the logic to see whether MDB file is loaded not in suitable time.

Regards,

Ethan