[gdal-dev] Need solution for C# exception: OSGeo.OGR.OgrPINVOKE

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] Need solution for C# exception: OSGeo.OGR.OgrPINVOKE

Genhan Chen
I am using ogr_csharp.dll in my c# program. See the following code snippet:

using OSGeo.OGR;

namespace Test
{
    public class Test
    {
        public Test()
        {
                ...
                  Ogr.RegisterAll();
        }      
    }
}

Then the following exception message was thrown out when the program is executed:

{"The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception."}        
System.Exception {System.TypeInitializationException}

Does anyone know how to resolve this issue?

Many thanks,

Genhan Chen
Cambridge Systematics, Inc.
555 12th Street, Suite 1600
Oakland CA 94607
tel  510 873 8700
fax  510 873 8701
e-mail [hidden email]
www.camsys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [gdal-dev] Need solution for C# exception: OSGeo.OGR.OgrPINVOKE

chqzeng
This post has NOT been accepted by the mailing list yet.
Hi I have exact same problem to setup the GDAL in C#.NET 2015, under windows 7 pro 64bit.

My steps are:
- downloaded the stable or daily stable release (same error later) from here.
- added the "...\bin" and "...\bin\gdal\csharp" to Environment Variable, setup a sample project,
- add the 4 "###sharp.dll" from csharp folder to project reference.
- import namespace:  using OSGeo.OGR; using OSGeo.OSR;  and add a simple line "Ogr.RegisterAll(); "

Then I can successfully build the project but with the following error msg.
I also tried all possible solutions by Google plus this forum such as this and this.
test all the x64/x86 , debug/release, switches, no luck.

Any comment is appreciated, thank you!

Chui

--------------------------error message --------------------------

Unhandled Exception: System.TypeInitializationException: The type initializer fo
r 'OSGeo.OGR.OgrPINVOKE' threw an exception. ---> System.TypeInitializationExcep
tion: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> Sy
stem.BadImageFormatException: An attempt was made to load a program with an inco
rrect format. (Exception from HRESULT: 0x8007000B)
   at OSGeo.OGR.OgrPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_Og
r(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, E
xceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate
, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDeleg
ate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, Exce
ptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, Exception
Delegate systemExceptionDelegate)
   at OSGeo.OGR.OgrPINVOKE.SWIGExceptionHelper..cctor()
   --- End of inner exception stack trace ---
   at OSGeo.OGR.OgrPINVOKE.SWIGExceptionHelper..ctor()
   at OSGeo.OGR.OgrPINVOKE..cctor()
   --- End of inner exception stack trace ---
   at OSGeo.OGR.OgrPINVOKE.RegisterAll()
   at OSGeo.OGR.Ogr.RegisterAll()
   at TestProj.Main(String[] args) in \user\Downloads\Workspace\TestProj\project.cs:line 47


and also the following log info:
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\TestProj\bin\Debug\TestProj.vshost.exe'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll'. Cannot find or open the PDB file.
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Cannot find or open the PDB file.
The thread 0x2228 has exited with code 0 (0x0).
The thread 0x1b30 has exited with code 0 (0x0).
The thread 0x2a64 has exited with code 0 (0x0).
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\TestProj\bin\Debug\TestProj.exe'. Symbols loaded.
The thread 0x2c20 has exited with code 0 (0x0).
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\TestProj\bin\Debug\ogr_csharp.dll'. Module was built without symbols.
Exception thrown: 'System.DllNotFoundException' in ogr_csharp.dll
Exception thrown: 'System.TypeInitializationException' in ogr_csharp.dll
Exception thrown: 'System.TypeInitializationException' in ogr_csharp.dll
An unhandled exception of type 'System.TypeInitializationException' occurred in ogr_csharp.dll
Additional information: The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception.

The program '[2244] TestProj.vshost.exe' has exited with code 0 (0x0)




Loading...