[gdal-dev] Need solution for C# setup, with error at OSGeo.OGR registration

C. Zeng chqzeng at gmail.com
Tue Aug 1 08:08:07 PDT 2017


​Hello all,

I am trying to setup the GDAL in C#.NET 2015, with an error at the
registration of the Ogr. A previous post
<http://osgeo-org.1560.x6.nabble.com/gdal-dev-Need-solution-for-C-exception-OSGeo-OGR-OgrPINVOKE-td5062693.html#a5329043>
stated the exact same problem but without a solution, I tried to reply in
that post but failed,thus send this email instead.

That previous post described my problem very well:

> "I am using *ogr_csharp.dl*l 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? "


Some more details for my case. My steps are:
- downloaded the stable or daily stable release (same error later) from here
<http://www.gisinternals.com/query.html?content=filelist&file=release-1800-x64-gdal-2-1-mapserver-7-0.zip>
.
- 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 tried all possible solutions by Google plus this forum such as this
<http://osgeo-org.1560.x6.nabble.com/gdal-dev-GDAL-OGR-64bit-PINVOKE-Exception-td3745305.html>
 and this
<http://osgeo-org.1560.x6.nabble.com/c-Bindings-in-Mono-Linux-td3758565.html#a3758569>
.
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)*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170801/ec0cf526/attachment-0001.html>


More information about the gdal-dev mailing list