C# ( vs10): "SharpMap.Layers. GdalRasterLayer" of type initializers throw an exception

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Aug 14, 2014 at 2:45 PM
public GdalRasterLayer GDlayer;
    private void buttongdal_Click(object sender, EventArgs e)
       Map map=new Map();
        const string  reltivePath="GeoData/Geotiff";
        GDlayer = new GdalRasterLayer("GeoTiff", @"C:\utm.tif");
I have installed the gdal.native and modified the app.config,Can somebody help me ?
Thank you!
Aug 14, 2014 at 8:36 PM
Remove the configuration from app.config.
After the build of your project is done, you should have the following folders in your output directory:
  • gdal
  • gdal\data
  • gdal\share
  • gdal\x86
  • gdal\x64
If that is not the case, show us
  • your project file
  • your packages.config file (if any)
Aug 15, 2014 at 8:37 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpMap.Extensions;
using SharpMap.Layers;
using SharpMap;
using SharpMap.Forms.ToolBar;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using BruTile.Cache;
using BruTile.Web;
using SharpMap.Layers;
using OSGeo.GDAL;

namespace UAV_Line
public partial class Form1 : Form
    public Form1()
    SharpMap.Map map = null;

    GdalRasterLayer GDlayer;
    private void button1_Click(object sender, EventArgs e)
        Map map = new Map();
        map.BackColor = Color.White;
        const string reltivePath = "GeoData/Geotiff";
        GDlayer = new GdalRasterLayer("GeoTiff", @"C:\utm.tif");
        GDlayer.UseRotation = true;

<?xml version="1.0"?>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<add key="FWToolsBinPath" value="C:\Program Files\FWTools2.4.7\bin" />
<add key="FWToolsProjLib" value="C:\Program Files\FWTools2.4.7\proj_lib" />
<add key="FWToolsGeoTiffCsv" value="C:\Program Files\FWTools2.4.7\data" />
<add key="FWToolsGdalData" value="C:\Program Files\FWTools2.4.7\data" />
<add key="FWToolsGdalDriver" value="C:\Program Files\FWTools2.4.7\plugins" />

Thanks for your reply FObermaier!
I have tried remove the configuration ,but it‘s no use
That's all my codes。 I build it with VS2010 X86 ,
I have checked the project and the folders(gdal gdal\data ……) all exist,my gdal_csharp.dll version is 1.0.4704.32537, I don't know if it concern。
Is there an integrity and independent demo ? Thank you very much!
Aug 18, 2014 at 7:54 AM
I asked for the *.csproj file and the packages.config file.
Do you have a GDAL installation that is available registered to the PATH environment variable?

The WinFormSamples project in the repository has a couple of samles using Gdal/Ogr functionality.