[FWTools] Fwd: C# OSR Error

Benjamin Chung bwchung at andrew.cmu.edu
Sat Jan 7 14:31:40 EST 2012


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):

System.AccessViolationException was unhandled
   Message=Attempted to read or write protected memory. This is often an 
indication that other memory is corrupt.
   Source=mscorlib
   StackTrace:
        at Microsoft.Win32.Win32Native.CoTaskMemFree(IntPtr ptr)
        at OSGeo.OSR.OsrPINVOKE.SpatialReference_ExportToWkt(HandleRef 
jarg1, String& jarg2)
        at OSGeo.OSR.SpatialReference.ExportToWkt(String& argout)
        at Tiler.Merger.Execute() in Tiler\Tiler.cs:line 132
        at 
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
        at 
Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost 
taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost 
taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, 
Boolean& taskResult)

And so on.

My environment variables look like this (Again, big block of text):
     ["ProgramData"]: "C:\\ProgramData"
     ["CommonProgramFiles(x86)"]: "C:\\Program Files (x86)\\Common Files"
     ["DevEnvDir"]: "C:\\Program Files (x86)\\Microsoft Visual Studio 
10.0\\Common7\\IDE\\"
     ["PROCESSOR_IDENTIFIER"]: "Intel64 Family 6 Model 42 Stepping 7, 
GenuineIntel"
     ["PYTHONPATH"]: "C:\\Program Files (x86)\\FWTools2.4.7\\pymod"
     ["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;"
     ["PROCESSOR_REVISION"]: "2a07"
     ["VS100COMNTOOLS"]: "C:\\Program Files (x86)\\Microsoft Visual 
Studio 10.0\\Common7\\Tools\\"
     ["PATHEXT"]: ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
     ["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;"
     ["FrameworkDir"]: "C:\\Windows\\Microsoft.NET\\Framework\\"
     ["LOCALAPPDATA"]: "C:\\Users\\Ben Chung\\AppData\\Local"
     ["PUBLIC"]: "C:\\Users\\Public"
     ["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;"
     ["GDAL_DATA"]: "C:\\Program Files (x86)\\FWTools2.4.7\\data"
     ["FrameworkDIR32"]: "C:\\Windows\\Microsoft.NET\\Framework\\"
     ["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
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"
     ["PROCESSOR_LEVEL"]: "6"
     ["NUMBER_OF_PROCESSORS"]: "8"
     ["FWTOOLS_DIR"]: "C:\\Program Files (x86)\\FWTools2.4.7"
     ["Framework35Version"]: "v3.5"
     ["VSINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft Visual Studio 
10.0\\"
     ["PROMPT"]: "$P$G"
     ["ProgramFiles(x86)"]: "C:\\Program Files (x86)"
     ["PROCESSOR_ARCHITEW6432"]: "AMD64"
     ["CommonProgramFiles"]: "C:\\Program Files (x86)\\Common Files"
     ["VCINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft Visual Studio 
10.0\\VC\\"
     ["asl.log"]: "Destination=file"
     ["PSModulePath"]: 
"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\"
     ["windows_tracing_flags"]: "3"
     ["ProgramW6432"]: "C:\\Program Files"
     ["ProgramFiles"]: "C:\\Program Files (x86)"
     ["GTK_BASEPATH"]: "C:\\Program Files (x86)\\GtkSharp\\2.12\\"
     ["FP_NO_HOST_CHECK"]: "NO"
     ["GDAL_DRIVER_PATH"]: "C:\\Program Files 
(x86)\\FWTools2.4.7\\gdal_plugins"
     ["RCAUTOPLAY"]: "C:\\Program Files (x86)\\Roxio\\OEM\\Roxio Central 
5\\"
     ["SystemRoot"]: "C:\\Windows"
     ["SESSIONNAME"]: "Console"
     ["CommonProgramW6432"]: "C:\\Program Files\\Common Files"
     ["FSHARPINSTALLDIR"]: "C:\\Program Files (x86)\\Microsoft F#\\v4.0\\"
     ["FrameworkVersion32"]: "v4.0.30319"
     ["BURN_AUTOPLAY"]: "C:\\Program Files (x86)\\Roxio\\OEM\\Roxio Burn\\"
     ["WindowsSdkDir"]: "C:\\Program Files (x86)\\Microsoft 
SDKs\\Windows\\v7.0A\\"
     ["FrameworkVersion"]: "v4.0.30319"
     ["HOMEDRIVE"]: "C:"
     ["GEOTIFF_CSV"]: "C:\\Program Files (x86)\\FWTools2.4.7\\data"
     ["PROCESSOR_ARCHITECTURE"]: "x86"
     ["OS"]: "Windows_NT"
     ["ComSpec"]: "C:\\Windows\\system32\\cmd.exe"
     ["PROJ_LIB"]: "C:\\Program Files (x86)\\FWTools2.4.7\\proj_lib"
     ["SystemDrive"]: "C:"
     ["windir"]: "C:\\Windows"
     ["ALLUSERSPROFILE"]: "C:\\ProgramData"

Here is the code I am using to set up GDAL:

             var  FwtoolsDir =Path.GetFullPath(@"C:\PROGRA~2\FWTOOL~1.7");
             Environment.SetEnvironmentVariable("FWTOOLS_DIR", FwtoolsDir);
             Environment.SetEnvironmentVariable("PATH", FwtoolsDir +@"\bin;"  + FwtoolsDir +@"\python;"  +Environment.GetEnvironmentVariable("PATH"));
             Environment.SetEnvironmentVariable("PYTHONPATH", FwtoolsDir+@"\pymod");
             Environment.SetEnvironmentVariable("PROJ_LIB", FwtoolsDir+@"\proj_lib");
             Environment.SetEnvironmentVariable("GEOTIFF_CSV", FwtoolsDir+@"\data");
             Environment.SetEnvironmentVariable("GDAL_DATA", FwtoolsDir+@"\data");
             Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", FwtoolsDir+@"\gdal_plugins");
             Gdal.AllRegister();


And the code that throws the error:

                         var  spt =new  OSGeo.OSR.SpatialReference("");
                         spt.SetFromUserInput(taskItem.GetMetadata("Projection"));

                         string  wkt;
                         spt.ExportToWkt(out  wkt);


The error happens in the ExportToWkt call.

Is there something I missed in my setup? Any help is greatly appreciated.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/fwtools/attachments/20120107/ab179e63/attachment.htm 


More information about the FWTools mailing list