Error when using the GDALRasterLayer

Topics: General Topics
Aug 22, 2007 at 9:17 AM
Hi all,

I have been experimenting with the GDALRasterLayer type from the Extensions (using the trunk of Build 25696) and I am consistently encountering a problem that I have not yet been able to resolve.

The relevant code is:
Layer_Raster = New SharpMap.Layers.GdalRasterLayer("Raster1", "D:\GIS\GLOBE\a10g\a10g")
Layer_Raster.MaxVisible = 1000
Layer_Raster.MinVisible = 1
myMap.Layers.Add(Layer_Raster)

The problem is that, upon trying to run the program the execution halts at line 48 of the GDalRasterLayer.cs file (the line contains the statement "OSGeo.GDAL.Gdal.AllRegister();"), with the following message appearing on the debug window: "A first chance exception of type 'System.TypeInitializationException' occurred in gdal_csharp.dll"

The same error occurs with various other raster files (other than GLOBE), so I consider it unlikely that the problem lies with the data itself.

I thought about the possibility of the GDAL/OGR libraries being out of date, but they are the very same ones included with the 25696 Extensions build.

I would appreciate any input as to the source of the problem and how it can be remedied. Thanks!

Cheers,
Dimitris



Aug 22, 2007 at 6:54 PM
Edited Aug 22, 2007 at 6:58 PM
Try downloading and installing the newest version of fwtools here http://fwtools.maptools.org/. After installation, copy all of the .dll files in the fwtools bin folder into the same folder as the .exe you are trying to run. That should fix it up.

I would also suggest downloading my new GDalRasterLayer code which adds a lot of functionality to the raster layer. http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=12134

Dan
Aug 23, 2007 at 8:52 AM

dan3258 wrote:
Try downloading and installing the newest version of fwtools here http://fwtools.maptools.org/. After installation, copy all of the .dll files in the fwtools bin folder into the same folder as the .exe you are trying to run. That should fix it up.

Unfortunately it did not. I got exactly the same error message after copying the 1.3.5 DLLs.


I would also suggest downloading my new GDalRasterLayer code which adds a lot of functionality to the raster layer. http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=12134

Dan

No joy with that either. Now it is generating the following error message:

System.TypeInitializationException was unhandled
Message="The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception."
Source="gdal_csharp"
TypeName="OSGeo.GDAL.GdalPINVOKE"
StackTrace:
at OSGeo.GDAL.GdalPINVOKE.AllRegister()
at OSGeo.GDAL.Gdal.AllRegister()
at SharpMap.Layers.GdalRasterLayer..ctor(String strLayerName, String imageFilename) in C:\Software\SharpMap-25696\Trunk\SharpMap.Extensions\Layers\GdalRasterLayer.cs:line 48
at GISTest1.Main.Form1_Load(Object sender, EventArgs e) in D:\GISTest1\Main.vb:line 91
at System.EventHandler.Invoke(Object sender, EventArgs e)
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.ContainerControl.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at GISTest1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Aug 23, 2007 at 2:06 PM
There is also a csharp folder in fwtools...try copying all of the dll's in that folder too...
Aug 23, 2007 at 2:26 PM
That's the only folder from which I copied the library files. Do I also need to copy DLLs from the \bin folder?
Aug 23, 2007 at 2:31 PM
Yes.
Aug 23, 2007 at 2:52 PM
I wasn't able to reference any of the DLLs on the fwtools\bin folder since they are not recognised as COM/.NET assemblies.
Aug 23, 2007 at 2:57 PM
You shouldnt need to reference them, just copy the dll's into the same folder as your executable.
Aug 23, 2007 at 3:09 PM
I did so. Now the application breaks at GDalRasterLayer.cs line 59 (line statement is: "set { _Filename = value; }"), with the following message:

A first chance exception of type 'System.ApplicationException' occurred in gdal_csharp.dll
A first chance exception of type 'System.Exception' occurred in SharpMap.Extensions.dll

Aug 24, 2007 at 8:51 PM
I had the same problem and finally fixed by downloading the most current build of SharpMap (at that time it was 24127). Adding the references to the csharp gdal libraries to SharpMap.Extensions:

gdal_csharp
gdalcont_csharp
ogr_csharp
osr_csharp

Then copied ALL the dll's out of the FWTools bin folder into the Extensions project bin folder. I'm sure I didn't have to copy all the dll's out of FWTools. But that worked so if it ain't broke don't fix it.
Jun 11, 2008 at 5:51 PM


rpierce wrote:
I had the same problem and finally fixed by downloading the most current build of SharpMap (at that time it was 24127). Adding the references to the csharp gdal libraries to SharpMap.Extensions:

gdal_csharp
gdalcont_csharp
ogr_csharp
osr_csharp

Then copied ALL the dll's out of the FWTools bin folder into the Extensions project bin folder. I'm sure I didn't have to copy all the dll's out of FWTools. But that worked so if it ain't broke don't fix it.



        I understand that it has been a while, but does anyone have a working copy that can load a raster, preferably a .sid file.  I've been having the same problems mentioned above with references the .dll's and getting the right ones.  Please any help would be apprieciated 
Jun 11, 2008 at 7:08 PM


        I understand that it has been a while, but does anyone have a working copy that can load a raster, preferably a .sid file.  I've been having the same problems mentioned above with references the .dll's and getting the right ones.  Please any help would be apprieciated 

Try my one off version of Sharpmap that is in the form of a patch here:

http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=SharpMap&DownloadId=24213

All of the dll's and references should be set up correctly (with no need for fwtools).
Jun 11, 2008 at 9:42 PM


dan3258 wrote:


        I understand that it has been a while, but does anyone have a working copy that can load a raster, preferably a .sid file.  I've been having the same problems mentioned above with references the .dll's and getting the right ones.  Please any help would be apprieciated 

Try my one off version of Sharpmap that is in the form of a patch here:

http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=SharpMap&DownloadId=24213

All of the dll's and references should be set up correctly (with no need for fwtools).


        Dan,
            Thanks for the quick reply.  I downloaded what you suggested.  When I load a raster (.sid)  I'm still getting "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception." error.  Am I missing something? 
Jun 11, 2008 at 10:16 PM
Did you try the DemoWinForm?  You can load your data up in that.  If that works, then you need to make sure you put all the files in the Dependencies folder into the directory of your executable.  If it doesn't work, then I have no clue.
Jun 11, 2008 at 10:40 PM


dan3258 wrote:
Did you try the DemoWinForm?  You can load your data up in that.  If that works, then you need to make sure you put all the files in the Dependencies folder into the directory of your executable.  If it doesn't work, then I have no clue.


        OK, I loaded all files from the depencies folder into DemoWinForm.  Now when I load a raster I get an error message my path included ex - C:\work\Ortho\County.sid, saying it is not a support format.  I was of the understanding that the GDAL and sharpmap would support MrSid images files.  Is this not the case, if not any suggestions?  Again thanks for the help with this....
Jun 12, 2008 at 3:13 PM
It looks like I included a bad version of one of the dll's.  I've made a work item with the correct dll as an attachment (which I'm sure is an abuse of the Issue Tracker).

http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=17020
Jun 12, 2008 at 5:21 PM


dan3258 wrote:
It looks like I included a bad version of one of the dll's.  I've made a work item with the correct dll as an attachment (which I'm sure is an abuse of the Issue Tracker).

http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=17020


            
            I've taken the new .dll and added it to my executable bin folder and in the dependcy folder.  When I try to load a .sid file I'm back to the 
            "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception." error.  The curious thing is, before I replaced the .dll I was at  least able to view the sample Geotiff, now when I load it is just a blank screen.  I would really like to be able to view a .sid in SharpMap.  Again; am I missing something, and thanks for all the help.
Jun 12, 2008 at 8:05 PM


weave128 wrote:


dan3258 wrote:
It looks like I included a bad version of one of the dll's.  I've made a work item with the correct dll as an attachment (which I'm sure is an abuse of the Issue Tracker).

http://www.codeplex.com/SharpMap/WorkItem/View.aspx?WorkItemId=17020


            
            I've taken the new .dll and added it to my executable bin folder and in the dependcy folder.  When I try to load a .sid file I'm back to the 
            "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception." error.  The curious thing is, before I replaced the .dll I was at  least able to view the sample Geotiff, now when I load it is just a blank screen.  I would really like to be able to view a .sid in SharpMap.  Again; am I missing something, and thanks for all the help.


Hi, I've got the same problem, I'm using this patch,  and when I try to load a .rik file in to the DemoWinForm I've got also the same error message saying: "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception."

Now I wonder if this patch is supporting .rik files?

Thanks for response!
Jun 12, 2008 at 8:27 PM

            I've taken the new .dll and added it to my executable bin folder and in the dependcy folder.  When I try to load a .sid file I'm back to the 
            "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception." error.  The curious thing is, before I replaced the .dll I was at  least able to view the sample Geotiff, now when I load it is just a blank screen.  I would really like to be able to view a .sid in SharpMap.  Again; am I missing something, and thanks for all the help.


It looks like there are a couple more dlls you need for sid support, I've included them in my work item.
Jun 12, 2008 at 9:05 PM


dan3258 wrote:

            I've taken the new .dll and added it to my executable bin folder and in the dependcy folder.  When I try to load a .sid file I'm back to the 
            "The type initilalizer for 'OSGeo.GDAL.gdalPINVOKE' threw an exception." error.  The curious thing is, before I replaced the .dll I was at  least able to view the sample Geotiff, now when I load it is just a blank screen.  I would really like to be able to view a .sid in SharpMap.  Again; am I missing something, and thanks for all the help.


It looks like there are a couple more dlls you need for sid support, I've included them in my work item.

Dan,
  You're the Man!   Thanks for all the help!
Developer
Jun 13, 2008 at 8:30 AM
Edited Jun 13, 2008 at 8:32 AM
You could also use the trunk includes most of Dan's patch and works with the newest gdal .net dlls. Here is a sample. You need to download the native dlls included in FWTools  2.2.0.

Jun 13, 2008 at 2:03 PM


pauldendulk wrote:
You could also use the trunk includes most of Dan's patch and works with the newest gdal .net dlls. Here is a sample. You need to download the native dlls included in FWTools  2.2.0.




Right...

Its probably best if you use the trunk...my patch is helpful for seeing what dll's from fwtools you need in your execution folder.