GDALRasterLayer doesn't work in .Net 4.0

Jan 28, 2011 at 10:59 PM

Works from the IDE but when running from the debug or release directory directory it throws this error (works fine when my app targets 3.5) ...

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************System.Exception: Couldn't load C:\Users\gene.sivorot\Downloads\Hillshade_pit2.img
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.   at SharpMap.Layers.GdalRasterLayer..ctor(String strLayerName, String imageFilename) in C:\Users\gene.sivorot\Downloads\SharpMap-78963\Trunk\SharpMap.Extensions\Layers\GdalRasterLayer.cs:line 419   at SharpMap.Layers.GdalRasterLayerCachingProxy..ctor(String strLayerName, String imageFilename) in C:\Users\gene.sivorot\Downloads\SharpMap-78963\Trunk\SharpMap.Extensions\Layers\GdalRasterLayerCachingProxy.cs:line 42   at GeoExplorer.ExplorerMap.LoadMapFile(String Filename) in C:\Users\gene.sivorot\Documents\Visual Studio 2010\Projects\GeoExplorer2010\GeoExplorer\Mapping\ExplorerMap.vb:line 118   at GeoExplorer.ExplorerMap.InitializeMapLayers() in C:\Users\gene.sivorot\Documents\Visual Studio 2010\Projects\GeoExplorer2010\GeoExplorer\Mapping\ExplorerMap.vb:line 101   at GeoExplorer.ExplorerMap..ctor(MapImage MapViewer, List`1 Sensors, String SystemNameSuffix) in C:\Users\gene.sivorot\Documents\Visual Studio 2010\Projects\GeoExplorer2010\GeoExplorer\Mapping\ExplorerMap.vb:line 43   at GeoExplorer.frmMain.InitializeMap() in C:\Users\gene.sivorot\Documents\Visual Studio 2010\Projects\GeoExplorer2010\GeoExplorer\Forms\Shared\frmMain.vb:line 2949   at GeoExplorer.frmMain.Form1_Load(Object sender, EventArgs e) in C:\Users\gene.sivorot\Documents\Visual Studio 2010\Projects\GeoExplorer2010\GeoExplorer\Forms\Shared\frmMain.vb:line 334   at System.Windows.Forms.Form.OnLoad(EventArgs e)   at System.Windows.Forms.Form.OnCreateControl()   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)   at System.Windows.Forms.Control.CreateControl()   at System.Windows.Forms.Control.WmShowWindow(Message& m)   at System.Windows.Forms.Control.WndProc(Message& m)   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)   at System.Windows.Forms.Form.WmShowWindow(Message& m)   at System.Windows.Forms.Form.WndProc(Message& m)   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************mscorlib    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll----------------------------------------GeoExplorer    Assembly Version: 3.0.10350.1384    Win32 Version: 3.0.10350.1384    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/GeoExplorer.exe----------------------------------------System.Windows.Forms    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll----------------------------------------System.Drawing    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll----------------------------------------System    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------cGeo.GeoExplorer.GeoExCGCFDesktopInterface    Assembly Version: 3.0.0.0    Win32 Version: 3.0.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/cGeo.GeoExplorer.GeoExCGCFDesktopInterface.DLL----------------------------------------cGeo.Framework.FF    Assembly Version: 3.0.0.0    Win32 Version: 3.0.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/cGeo.Framework.FF.DLL----------------------------------------System.Configuration    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll----------------------------------------Microsoft.VisualBasic    Assembly Version: 10.0.0.0    Win32 Version: 10.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll----------------------------------------System.Core    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll----------------------------------------System.Xml    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll----------------------------------------cGeo.Quadrant.QuadrantCGCFDesktopInterface    Assembly Version: 3.0.0.0    Win32 Version: 3.0.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/cGeo.Quadrant.QuadrantCGCFDesktopInterface.DLL----------------------------------------cGeo.Gemeni.GemeniCGCFDesktopInterface    Assembly Version: 3.0.0.0    Win32 Version: 3.0.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/cGeo.Gemeni.GemeniCGCFDesktopInterface.DLL----------------------------------------System.Management    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Management/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Management.dll----------------------------------------cGeo.Tension.TensionCGCFDesktopInterface    Assembly Version: 3.0.0.0    Win32 Version: 3.0.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/cGeo.Tension.TensionCGCFDesktopInterface.DLL----------------------------------------fyc3dycg    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------qiugpxxo    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------t0pyi0fr    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------aeh3t1pw    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------qqcnhaho    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------jwhxcqw2    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------fgxsv5uz    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------bmwm3myq    Assembly Version: 3.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------SharpMap.UI    Assembly Version: 0.9.3997.20653    Win32 Version: 0.9.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/SharpMap/SharpMap.UI.DLL----------------------------------------SharpMap    Assembly Version: 0.9.3995.18044    Win32 Version: 0.9.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/SharpMap/SharpMap.DLL----------------------------------------System.Data    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll----------------------------------------System.Numerics    Assembly Version: 4.0.0.0    Win32 Version: 4.0.30319.1 built by: RTMRel    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll----------------------------------------SharpMap.Extensions    Assembly Version: 0.9.3997.20918    Win32 Version: 0.9.0.0    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/SharpMap/SharpMap.Extensions.DLL----------------------------------------gdal_csharp    Assembly Version: 1.0.3671.21225    Win32 Version: 1.0.3671.21225    CodeBase: file:///C:/Users/gene.sivorot/Documents/Visual%20Studio%202010/Projects/GeoExplorer2010/GeoExplorer/bin/Debug/SharpMap/gdal_csharp.DLL----------------------------------------
************** JIT Debugging **************To enable just-in-time (JIT) debugging, the .config file for thisapplication or computer (machine.config) must have thejitDebugging value set in the system.windows.forms section.The application must also be compiled with debuggingenabled.
For example:
<configuration>    <system.windows.forms jitDebugging="true" /></configuration>
When JIT debugging is enabled, any unhandled exceptionwill be sent to the JIT debugger registered on the computerrather than be handled by this dialog box.

Coordinator
Jan 31, 2011 at 7:47 AM

I have no idea why it would run from within the VS IDE but not when running from the respective folders.

Could you compare Environment variables for differences when running from ide and when not?

Hth FObermaier

May 4, 2011 at 4:38 AM

Would this have to do with the issues I'm having in .Net 4 and GDAL: http://osgeo-org.1803224.n2.nabble.com/gdal-dev-c-binding-and-net4-td5375283.html

Specifically, this issue: http://trac.osgeo.org/gdal/ticket/3560

Coordinator
May 4, 2011 at 1:05 PM
Edited May 4, 2011 at 2:04 PM

Hello gsivorot,

you can try for yourself:

- Download gdal-18-1600-core.msi from http://vbkto.dyndns.org/sdk/PackageList.aspx?file=release-1600-gdal-1-8-mapserver-5-6.zip and install.

- Replace GDAL*, OGR*, OSR* libraries in SharpMap\ExternalReferences\References4SharpMapExtensions (or s.th. like that) with the ones provided by the installer.

- change FWToolsXXX settings in App.config to values appropriate for the above installation.

- communicate your trouble/success

Hth FObermaier

May 5, 2011 at 4:33 AM
Edited May 5, 2011 at 4:34 AM

Hi FObermaier,

Thanks for the instructions.  

- I downloaded the GDAL version you listed
- updated the GDAL refs in SharpMap.Extensions (trunk)
- had to up the .Net framework version for the project to .Net 4.0
- re-compiled

It seems to be working perfectly now.  Unfortunately, I seem to have lost .ecw file support for the GDAL raster layer.  Is there anyway to get that to work without having to compile GDAL myself, because it looks like it could be painful.  I'm guessing you won't be updating the refs for GDAL until a new version of FWTools comes out?

Thanks,

Gene

Coordinator
May 5, 2011 at 7:05 AM

Hello Gene,

fine that it works for you. If you would rather go for .Net20, you need to choose from http://vbkto.dyndns.org/sdk/PackageList.aspx?file=release-1400-gdal-1-8-mapserver-5-6.zip

For ecw, mrsid and oracle support there are additional install packages on that page.

I think there won't be a new version of FWTools, iirc Frank Warmadam has given that up in favor of OSGeo4W. Unfortunately there are no csharp bindings in it yet.

Hth FObermaier

May 5, 2011 at 6:13 PM

Hi FObermaier,

I have copied over the GDAL plugins (including ECW) to a 'pugins' folder to the GDAL core/FWTools Path that I'm using.  Then I set the FWToolsGdalDriver path in my app to the 'plugins' folder but it doesn't seem to be picking up the plugins.  Did I miss a step?

Thanks,

Gene

Coordinator
May 6, 2011 at 7:51 AM
Edited May 6, 2011 at 10:15 AM

Gene,

Try changing in FWToolsHelper class the function call

SetFWToolsEnvironmentVariable("FWToolsGdalDriver", "GDAL_DRIVER");

to

SetFWToolsEnvironmentVariable("FWToolsGdalDriver", "GDAL_DRIVER_PATH");

If that does not work, could you please check with DependencyWalker whether all library dependencies are met for gdal_ecw...dll? If not you may need to add some path settings.
In my case there was a reference missing from iconv.dll to msvcr80.dll and one to ieshims.dll.

Hth FObermaier

Developer
May 9, 2012 at 5:40 AM

A newer version of gdal_csharp also worked for me. The website where you can download the newer version is relocated to: http://www.gisinternals.com/sdk/