0

I am trying to create a rasterlayer from the example geotiffs. I have downloaded the GDAL native and plugins NuGets. However whenever I run the project it always returns a not very helpful error: "The type initializer for 'SharpMap.Layers.GdalRasterLayer' threw an exception."

I know the sharp map elements are working as I can load in a vector layer and display it no problem its just the GDAL side.

This is the code I am using. I have checked and the GDAL directories are included in the bin folder when running.

LayerGroup group = new LayerGroup("OS");
        //group.SRID = 27700;
        group.LayerName = "Raster250";

        var di = new DirectoryInfo(@"C:\OS Maps Current\GeoTiff");
        foreach (var fi in di.GetFiles("*.tif"))
        {
            try
            {
                SharpMap.Layers.GdalRasterLayer layer = new GdalRasterLayer(
                    fi.Name, fi.FullName);
                group.Layers.Add(layer);
            }
            catch (Exception ex)
            {
            }
        }

        m_Map.Layers.Add(group);

Any ideas gratefully received.

Chris

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
ChrisB
  • 53
  • 7
  • I have managed to get a working project in winforms, there is something when about MVC that is causing the issue. I have tried building the map both in the application start and in a controller with no luck. – ChrisB Jan 05 '14 at 13:10
  • I found the answer here http://stackoverflow.com/questions/14353502/exception-while-using-gdl-in-c-sharp made sure all of these files were there and hey presto it works. – ChrisB Jan 06 '14 at 08:43

0 Answers0