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

Tamas Szekeres szekerest at gmail.com
Tue Aug 1 09:15:18 PDT 2017


Hi,

You probably have multiple dll dependencies availabe in the path. Try copying all the dependencies from the same package to the location where your excutable is running.

Best regards,

Tamas

Az iPhone-omról küldve

2017. aug. 1. dátummal, 17:08 időpontban C. Zeng <chqzeng at gmail.com> írta:

> ​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 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.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? "
> 
> Some more details for my case. 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 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)
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170801/b1c4f129/attachment-0001.html>


More information about the gdal-dev mailing list