[Gdal-dev] unable to initialize OGR datasource using C#

Eduardo Patto Kanegae eduardo.kanegae at inflor.com.br
Mon Jun 25 17:46:36 EDT 2007


Hi,

I´d like to run some C# benchmarks using OGR x ArcObjects but I´m 
getting some errors with OGR.

I´m running VisualStudio.NET 2005 with Windows XP Pro, created a new 
Windows application project,
added references for gdal_csharp.dll, gdalconst_csharp.dll, 
ogr_csharp.dll and osr_csharp.dll
and also C:\Program files\FWTools1.3.2\bin as a project reference path.

Then I added " using OSGeo.OGR " at the begining of my form code but 
when I try to run it,
it fails at the first line: Ogr.RegisterAll();

Ogr.RegisterAll();
OSGeo.OGR.DataSource oDS = Ogr.Open("D:\\myshapefile.shp", 0);
if (oDS == null)
{
    MessageBox.Show("DataSource open error!");
}
else
{
    Driver oDrv = oDS.GetDriver();
    if (oDrv == null)
    {
        MessageBox.Show("getDriver error!");
    }
    else
    {
        MessageBox.Show(oDrv.name);
    }
}

What might be wrong?

The error handler only gives me:

System.TypeInitializationException was unhandled
  Message="The type initializer for 'OSGeo.OGR.Ogr' threw an exception."
  Source="ogr_csharp"
  TypeName="OSGeo.OGR.Ogr"

thanks,

Eduardo Patto Kanegae
Consultor GIS
Tel: +55(27)2122-0888
Cel: +55(27)8155-2990
Fax: +55(27)2122-0861
eduardo.kanegae at inflor.com.br <mailto:eduardo.kanegae at inflor.com.br>
www.inflor.com.br <http://www.inflor.com.br>



More information about the Gdal-dev mailing list