<div>Hi,</div><div><br></div><div>I downloaded FWTools for Windows 32 bit at <a href="http://fwtools.maptools.org/" target="_blank">http://fwtools.maptools.org/</a> and used dlls in csharp folder in my simple .NET Winform application. I'm trying to use OGR to convert only location data in MapInfo file to GML. However, I always gets the error System.AccessViolationException whenever calling to ExportTo*() methods on Geometry object. But what surprises me is that the exception doesn't happen if I run the program in Debug mode (in Visual Studio, press F5 key to launch debugging). And the exception raises when I run by Ctrl + F5 (without debugging). Below is my code in the program:</div>
<div><br></div><div>=== SAMPLE CODE ====</div><div><br></div><div><div>var pathValue = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);</div><div>pathValue += @";C:\Program Files (x86)\FWTools2.4.7\bin";</div>
<div>Environment.SetEnvironmentVariable("PATH", pathValue, EnvironmentVariableTarget.Process);</div>
<div>Ogr.RegisterAll();</div></div><div><br></div><div><div>using (var ds = Ogr.Open("EXTRACT_POLYGON.tab", 0))</div><div><div>{</div><div><span style="white-space:pre-wrap">        </span>for (int iLayer = 0; iLayer < ds.GetLayerCount(); iLayer++)</div>
<div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">                </span>var layer = ds.GetLayerByIndex(iLayer);</div><div><span style="white-space:pre-wrap">                </span>if (layer == null)</div>
<div><span style="white-space:pre-wrap">                </span>{</div><div><span style="white-space:pre-wrap">                        </span>throw new ArgumentException("Layer not found");</div><div><span style="white-space:pre-wrap">                </span>}</div>
<div><br></div><div><span style="white-space:pre-wrap">                </span>using (layer)</div><div><span style="white-space:pre-wrap">                </span>using (var feature = layer.GetNextFeature())</div><div>
<span style="white-space:pre-wrap">                </span>using (var geo = feature.GetGeometryRef())</div><div><span style="white-space:pre-wrap">                </span>{</div><div><span style="white-space:pre-wrap">                        </span>var gmlContent = geo.ExportToGML(); // <=== exception throws, this happens for ExportToJson(), ExportToKML() ...</div>
<div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}</div></div><div><br></div><div>===== END ======</div><div><br></div><div>And below is the exception</div>
<div><br></div><div><div>System.AccessViolationException was unhandled</div><div> Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</div><div> Source=ogr_csharp</div>
<div> StackTrace:</div><div> at OSGeo.OGR.OgrPINVOKE.Geometry_ExportToGML(HandleRef jarg1)</div><div> at OSGeo.OGR.Geometry.ExportToGML()</div><div> at TestApp.MainForm.btnRequestToken_Click(Object sender, EventArgs e) in D:\TestApp\MainForm.cs:line 56</div>
</div><div><br></div><div><br></div><div>I also get the same exception when retrieving the driver too. For example, this code will raise the System.AccessViolationException : var driver = org.Ogr.GetDriverByName("GML");</div>
<div><br></div><div><br></div><div>Did I miss something ? Any help is greatly appreciated</div><div><br></div><div><br></div>-- <br>Thanks,<br>Duy Lam<br>
</div>