<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I am using the GDAL/OSR C# interface in a build-integrated
environment, and I am having some issues with them. What appears to
be happening is that the drivers load, but are invalid, so
Gdal.AllRegister() doesn't throw an exception, but when I call
ExportToWkt I get the error (caution, big block of text):<br>
<br>
System.AccessViolationException was unhandled<br>
Message=Attempted to read or write protected memory. This is often
an indication that other memory is corrupt.<br>
Source=mscorlib<br>
StackTrace:<br>
at Microsoft.Win32.Win32Native.CoTaskMemFree(IntPtr ptr)<br>
at
OSGeo.OSR.OsrPINVOKE.SpatialReference_ExportToWkt(HandleRef jarg1,
String& jarg2)<br>
at OSGeo.OSR.SpatialReference.ExportToWkt(String& argout)<br>
at Tiler.Merger.Execute() in Tiler\Tiler.cs:line 132<br>
at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()<br>
at
Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost
taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost
taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask,
Boolean& taskResult)<br>
<br>
And so on.<br>
<br>
My environment variables look like this (Again, big block of text):<br>
["ProgramData"]: "C:\\ProgramData"<br>
["CommonProgramFiles(x86)"]: "C:\\Program Files (x86)\\Common
Files"<br>
["DevEnvDir"]: "C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\Common7\\IDE\\"<br>
["PROCESSOR_IDENTIFIER"]: "Intel64 Family 6 Model 42 Stepping 7,
GenuineIntel"<br>
["PYTHONPATH"]: "C:\\Program Files (x86)\\FWTools2.4.7\\pymod"<br>
["INCLUDE"]: "C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\VC\\INCLUDE;C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\VC\\ATLMFC\\INCLUDE;C:\\Program Files (x86)\\Microsoft
SDKs\\Windows\\v7.0A\\include;"<br>
["PROCESSOR_REVISION"]: "2a07"<br>
["VS100COMNTOOLS"]: "C:\\Program Files (x86)\\Microsoft Visual
Studio 10.0\\Common7\\Tools\\"<br>
["PATHEXT"]:
".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"<br>
["LIBPATH"]:
"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;C:\\Windows\\Microsoft.NET\\Framework\\v3.5;C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\VC\\LIB;C:\\Program Files
(x86)\\Microsoft Visual Studio 10.0\\VC\\ATLMFC\\LIB;"<br>
["FrameworkDir"]: "C:\\Windows\\Microsoft.NET\\Framework\\"<br>
["LOCALAPPDATA"]: "C:\\Users\\Ben Chung\\AppData\\Local"<br>
["PUBLIC"]: "C:\\Users\\Public"<br>
["LIB"]: "C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\VC\\LIB;C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\VC\\ATLMFC\\LIB;C:\\Program Files (x86)\\Microsoft
SDKs\\Windows\\v7.0A\\lib;"<br>
["GDAL_DATA"]: "C:\\Program Files (x86)\\FWTools2.4.7\\data"<br>
["FrameworkDIR32"]: "C:\\Windows\\Microsoft.NET\\Framework\\"<br>
["Path"]: "C:\\Program Files
(x86)\\FWTools2.4.7\\bin;C:\\Program Files
(x86)\\FWTools2.4.7\\python;C:\\Program Files (x86)\\Microsoft
F#\\v4.0\\;C:\\Program Files (x86)\\Microsoft Visual Studio
10.0\\VSTSDB\\Deploy;C:\\Program Files (x86)\\Microsoft Visual
Studio 10.0\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft
Visual Studio 10.0\\VC\\BIN;C:\\Program Files (x86)\\Microsoft
Visual Studio
10.0\\Common7\\Tools;C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319;C:\\Windows\\Microsoft.NET\\Framework\\v3.5;C:\\Program
Files (x86)\\Microsoft Visual Studio
10.0\\VC\\VCPackages;C:\\Program Files (x86)\\HTML Help
Workshop;C:\\Program Files (x86)\\Microsoft
SDKs\\Windows\\v7.0A\\bin\\NETFX 4.0 Tools;C:\\Program Files
(x86)\\Microsoft SDKs\\Windows\\v7.0A\\bin;C:\\Program Files\\Common
Files\\Microsoft Shared\\Windows Live;C:\\Program Files
(x86)\\Common Files\\Microsoft Shared\\Windows
Live;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Progra<br>
m Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common
Files\\Intel\\WirelessCommon\\;C:\\Program Files (x86)\\Windows
Live\\Shared;C:\\Program Files (x86)\\Common Files\\Roxio
Shared\\DLLShared\\;C:\\Program Files (x86)\\Common Files\\Roxio
Shared\\OEM\\DLLShared\\;C:\\Program Files (x86)\\Common
Files\\Roxio Shared\\OEM\\DLLShared\\;C:\\Program Files
(x86)\\Common Files\\Roxio
Shared\\OEM\\12.0\\DLLShared\\;C:\\Program Files
(x86)\\Roxio\\OEM\\AudioCore\\;c:\\Program Files (x86)\\Microsoft
SQL Server\\100\\Tools\\Binn\\;c:\\Program Files\\Microsoft SQL
Server\\100\\Tools\\Binn\\;c:\\Program Files\\Microsoft SQL
Server\\100\\DTS\\Binn\\;C:\\Program Files
(x86)\\GtkSharp\\2.12\\bin"<br>
["PROCESSOR_LEVEL"]: "6"<br>
["NUMBER_OF_PROCESSORS"]: "8"<br>
["FWTOOLS_DIR"]: "C:\\Program Files (x86)\\FWTools2.4.7"<br>
["Framework35Version"]: "v3.5"<br>
["VSINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft Visual
Studio 10.0\\"<br>
["PROMPT"]: "$P$G"<br>
["ProgramFiles(x86)"]: "C:\\Program Files (x86)"<br>
["PROCESSOR_ARCHITEW6432"]: "AMD64"<br>
["CommonProgramFiles"]: "C:\\Program Files (x86)\\Common Files"<br>
["VCINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft Visual
Studio 10.0\\VC\\"<br>
["asl.log"]: "Destination=file"<br>
["PSModulePath"]:
"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\"<br>
["windows_tracing_flags"]: "3"<br>
["ProgramW6432"]: "C:\\Program Files"<br>
["ProgramFiles"]: "C:\\Program Files (x86)"<br>
["GTK_BASEPATH"]: "C:\\Program Files (x86)\\GtkSharp\\2.12\\"<br>
["FP_NO_HOST_CHECK"]: "NO"<br>
["GDAL_DRIVER_PATH"]: "C:\\Program Files
(x86)\\FWTools2.4.7\\gdal_plugins"<br>
["RCAUTOPLAY"]: "C:\\Program Files (x86)\\Roxio\\OEM\\Roxio
Central 5\\"<br>
["SystemRoot"]: "C:\\Windows"<br>
["SESSIONNAME"]: "Console"<br>
["CommonProgramW6432"]: "C:\\Program Files\\Common Files"<br>
["FSHARPINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft
F#\\v4.0\\"<br>
["FrameworkVersion32"]: "v4.0.30319"<br>
["BURN_AUTOPLAY"]: "C:\\Program Files (x86)\\Roxio\\OEM\\Roxio
Burn\\"<br>
["WindowsSdkDir"]: "C:\\Program Files (x86)\\Microsoft
SDKs\\Windows\\v7.0A\\"<br>
["FrameworkVersion"]: "v4.0.30319"<br>
["HOMEDRIVE"]: "C:"<br>
["GEOTIFF_CSV"]: "C:\\Program Files (x86)\\FWTools2.4.7\\data"<br>
["PROCESSOR_ARCHITECTURE"]: "x86"<br>
["OS"]: "Windows_NT"<br>
["ComSpec"]: "C:\\Windows\\system32\\cmd.exe"<br>
["PROJ_LIB"]: "C:\\Program Files (x86)\\FWTools2.4.7\\proj_lib"<br>
["SystemDrive"]: "C:"<br>
["windir"]: "C:\\Windows"<br>
["ALLUSERSPROFILE"]: "C:\\ProgramData"<br>
<br>
Here is the code I am using to set up GDAL:<br>
<br>
<title>Snippet</title>
<pre style="font-family:Consolas;font-size:13;color:black;background:white;"><span style="color:blue;"> var</span> FwtoolsDir = <span style="color:#2b91af;">Path</span>.GetFullPath(<span style="color:#a31515;">@"C:\PROGRA~2\FWTOOL~1.7"</span>);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"FWTOOLS_DIR"</span>, FwtoolsDir);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"PATH"</span>, FwtoolsDir + <span style="color:#a31515;">@"\bin;"</span> + FwtoolsDir + <span style="color:#a31515;">@"\python;"</span> + <span style="color:#2b91af;">Environment</span>.GetEnvironmentVariable(<span style="color:#a31515;">"PATH"</span>));
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"PYTHONPATH"</span>, FwtoolsDir+<span style="color:#a31515;">@"\pymod"</span>);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"PROJ_LIB"</span>, FwtoolsDir+<span style="color:#a31515;">@"\proj_lib"</span>);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"GEOTIFF_CSV"</span>, FwtoolsDir+<span style="color:#a31515;">@"\data"</span>);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"GDAL_DATA"</span>, FwtoolsDir+<span style="color:#a31515;">@"\data"</span>);
<span style="color:#2b91af;">Environment</span>.SetEnvironmentVariable(<span style="color:#a31515;">"GDAL_DRIVER_PATH"</span>, FwtoolsDir+<span style="color:#a31515;">@"\gdal_plugins"</span>);
<span style="color:#2b91af;">Gdal</span>.AllRegister();
</pre>
And the code that throws the error:<br>
<br>
<title>Snippet</title>
<pre style="font-family:Consolas;font-size:13;color:black;background:white;"> <span style="color:blue;">var</span> spt = <span style="color:blue;">new</span> OSGeo.OSR.<span style="color:#2b91af;">SpatialReference</span>(<span style="color:#a31515;">""</span>);
spt.SetFromUserInput(taskItem.GetMetadata(<span style="color:#a31515;">"Projection"</span>));
<span style="color:blue;">string</span> wkt;
spt.ExportToWkt(<span style="color:blue;">out</span> wkt);
</pre>
<br>
The error happens in the ExportToWkt call.<br>
<br>
Is there something I missed in my setup? Any help is greatly
appreciated.<br>
<br>
<title>S</title>
<br>
<br>
</body>
</html>