<div dir="ltr"><div class="gmail_default" style="font-size:small">Thank you Eric and Tamas,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I have switched to python with Gdal, due to this setup issue with C# and other platform consideration. Thank you two for the help!.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Best,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Chui,</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 4:18 PM, Eric Wenger ARA/SED <span dir="ltr"><<a href="mailto:ewenger@ara.com" target="_blank">ewenger@ara.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_-3106728091040260095WordSection1">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Chui,<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">An example here is that you need to have proj.dll in the path so that gdal.dll will load from the PInvoke.  You can use dependency walker to find other dependencies.<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></b></p>
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> gdal-dev [mailto:<a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@<wbr>lists.osgeo.org</a>]
<b>On Behalf Of </b>Tamas Szekeres<br>
<b>Sent:</b> Tuesday, August 01, 2017 12:15 PM<br>
<b>To:</b> C. Zeng<br>
<b>Cc:</b> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<b>Subject:</b> Re: [gdal-dev] Need solution for C# setup, with error at OSGeo.OGR registration<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal">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.<u></u><u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal">Best regards,<u></u><u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div id="m_-3106728091040260095AppleMailSignature">
<p class="MsoNormal">Tamas<br>
<br>
Az iPhone-omról küldve<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
2017. aug. 1. dátummal, 17:08 időpontban C. Zeng <<a href="mailto:chqzeng@gmail.com" target="_blank">chqzeng@gmail.com</a>> írta:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal">​Hello all,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am trying to setup the GDAL in C#.NET 2015, with an error at the registration of the Ogr. A
<a href="http://osgeo-org.1560.x6.nabble.com/gdal-dev-Need-solution-for-C-exception-OSGeo-OGR-OgrPINVOKE-td5062693.html#a5329043" target="_blank">
previous post</a> stated the exact same problem but without a solution, I tried to reply in that post but failed,thus send this email instead. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">That previous post described my problem very well:  <u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><span style="font-family:"Book Antiqua","serif";color:black">"I am using <b>ogr_csharp.dl</b>l in my c# program. See the following code snippet:</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:blue">using</span><span style="font-family:"Book Antiqua","serif";color:black"> OSGeo.OGR;</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:blue">namespace</span><span style="font-family:"Book Antiqua","serif";color:black"> Test</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">{</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">    </span><span style="font-family:"Book Antiqua","serif";color:blue">public</span><span style="font-family:"Book Antiqua","serif";color:black"> </span><span style="font-family:"Book Antiqua","serif";color:blue">class</span><span style="font-family:"Book Antiqua","serif";color:black"> </span><span style="font-family:"Book Antiqua","serif";color:#4181c0">Test</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">    {</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">        </span><span style="font-family:"Book Antiqua","serif";color:blue">public</span><span style="font-family:"Book Antiqua","serif";color:black"> Test()</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">        {</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">                ...</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">                  </span><span style="font-family:"Book Antiqua","serif";color:#4181c0">Ogr</span><span style="font-family:"Book Antiqua","serif";color:black">.RegisterAll();</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">        }      </span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">    }</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">}</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">Then the following exception message was thrown out when the program is executed:</span><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><b><span style="font-family:"Book Antiqua","serif";color:black">{"The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception."}        </span></b><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><b><span style="font-family:"Book Antiqua","serif";color:black">System.Exception {System.<wbr>TypeInitializationException}</span></b><span style="font-family:"Verdana","sans-serif";color:black"> <br>
</span><span style="font-family:"Book Antiqua","serif";color:black">Does anyone know how to resolve this issue?</span><span style="font-family:"Verdana","sans-serif";color:black"> "</span><u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Some more details for my case. <span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black">My steps are: </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black">- downloaded the stable or daily stable release (same error later) from </span><a href="http://www.gisinternals.com/query.html?content=filelist&file=release-1800-x64-gdal-2-1-mapserver-7-0.zip" target="_blank"><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:#551a8b">here</span></a><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black">. <br>
- added the "...\bin" and "...\bin\gdal\csharp" to Environment Variable, setup a sample project, <br>
- add the 4 "###sharp.dll" from csharp folder to project reference. <br>
- import namespace:  using OSGeo.OGR; using OSGeo.OSR;  and add a simple line "Ogr.RegisterAll(); " <br>
<br>
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 </span><a href="http://osgeo-org.1560.x6.nabble.com/gdal-dev-GDAL-OGR-64bit-PINVOKE-Exception-td3745305.html" target="_blank"><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:#551a8b">this</span></a><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black"> and </span><a href="http://osgeo-org.1560.x6.nabble.com/c-Bindings-in-Mono-Linux-td3758565.html#a3758569" target="_blank"><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:#551a8b">this</span></a><span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black">. <br>
test all the x64/x86 , debug/release, switches, no luck. <br>
<br>
Any comment is appreciated, thank you! <br>
<br>
Chui <br>
</span><br>
<br>
<span style="font-size:12.5pt;font-family:"Verdana","sans-serif";color:black"><br>
--------------------------<wbr>error message -------------------------- <br>
<br>
<i>Unhandled Exception: System.<wbr>TypeInitializationException: The type initializer fo <br>
r 'OSGeo.OGR.OgrPINVOKE' threw an exception. ---> System.<wbr>TypeInitializationExcep <br>
tion: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> Sy <br>
stem.BadImageFormatException: An attempt was made to load a program with an inco <br>
rrect format. (Exception from HRESULT: 0x8007000B) <br>
   at OSGeo.OGR.OgrPINVOKE.<wbr>SWIGExceptionHelper.<wbr>SWIGRegisterExceptionCallbacks<wbr>_Og <br>
r(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, E <br>
xceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate <br>
, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDeleg <br>
ate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, Exce <br>
ptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, Exception <br>
Delegate systemExceptionDelegate) <br>
   at OSGeo.OGR.OgrPINVOKE.<wbr>SWIGExceptionHelper..cctor() <br>
   --- End of inner exception stack trace --- <br>
   at OSGeo.OGR.OgrPINVOKE.<wbr>SWIGExceptionHelper..ctor() <br>
   at OSGeo.OGR.OgrPINVOKE..cctor() <br>
   --- End of inner exception stack trace --- <br>
   at OSGeo.OGR.OgrPINVOKE.<wbr>RegisterAll() <br>
   at OSGeo.OGR.Ogr.RegisterAll() <br>
   at TestProj.Main(String[] args) in \user\Downloads\Workspace\<wbr>TestProj\project.cs:line 47</i><br>
<br>
and also the following log info: <br>
<i>'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_64\mscorlib\v4.0_<wbr>4.0.0.0__b77a5c561934e089\<wbr>mscorlib.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\<wbr>Microsoft.VisualStudio.<wbr>HostingProcess.Utilities\14.0.<wbr>0.0__b03f5f7f11d50a3a\<wbr>Microsoft.VisualStudio.<wbr>HostingProcess.Utilities.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.<wbr>Windows.Forms\v4.0_4.0.0.0__<wbr>b77a5c561934e089\System.<wbr>Windows.Forms.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System\v4.0_<wbr>4.0.0.0__b77a5c561934e089\<wbr>System.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.<wbr>Drawing\v4.0_4.0.0.0__<wbr>b03f5f7f11d50a3a\System.<wbr>Drawing.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\<wbr>Microsoft.VisualStudio.<wbr>HostingProcess.Utilities.Sync\<wbr>14.0.0.0__b03f5f7f11d50a3a\<wbr>Microsoft.VisualStudio.<wbr>HostingProcess.Utilities.Sync.<wbr>dll'. Cannot find or open
 the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\<wbr>Microsoft.VisualStudio.<wbr>Debugger.Runtime\14.0.0.0__<wbr>b03f5f7f11d50a3a\Microsoft.<wbr>VisualStudio.Debugger.Runtime.<wbr>dll'.<br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\<wbr>TestProj\bin\Debug\TestProj.<wbr>vshost.exe'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.Core\<wbr>v4.0_4.0.0.0__<wbr>b77a5c561934e089\System.Core.<wbr>dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.Xml.<wbr>Linq\v4.0_4.0.0.0__<wbr>b77a5c561934e089\System.Xml.<wbr>Linq.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.Data.<wbr>DataSetExtensions\v4.0_4.0.0.<wbr>0__b77a5c561934e089\System.<wbr>Data.DataSetExtensions.dll'. Cannot find or
 open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\Microsoft.<wbr>CSharp\v4.0_4.0.0.0__<wbr>b03f5f7f11d50a3a\Microsoft.<wbr>CSharp.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_64\System.Data\<wbr>v4.0_4.0.0.0__<wbr>b77a5c561934e089\System.Data.<wbr>dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.Net.<wbr>Http\v4.0_4.0.0.0__<wbr>b03f5f7f11d50a3a\System.Net.<wbr>Http.dll'. Cannot find or open the PDB file. <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded 'C:\WINDOWS\<a href="http://Microsoft.Net" target="_blank">Microsoft.Net</a>\<wbr>assembly\GAC_MSIL\System.Xml\<wbr>v4.0_4.0.0.0__<wbr>b77a5c561934e089\System.Xml.<wbr>dll'. Cannot find or open the PDB file. <br>
The thread 0x2228 has exited with code 0 (0x0). <br>
The thread 0x1b30 has exited with code 0 (0x0). <br>
The thread 0x2a64 has exited with code 0 (0x0). <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\<wbr>TestProj\bin\Debug\TestProj.<wbr>exe'. Symbols loaded. <br>
The thread 0x2c20 has exited with code 0 (0x0). <br>
'TestProj.vshost.exe' (CLR v4.0.30319: TestProj.vshost.exe): Loaded '\user\Downloads\Gdal_folder\<wbr>TestProj\bin\Debug\ogr_csharp.<wbr>dll'. Module was built without symbols. <br>
Exception thrown: 'System.DllNotFoundException' in ogr_csharp.dll <br>
Exception thrown: 'System.<wbr>TypeInitializationException' in ogr_csharp.dll <br>
Exception thrown: 'System.<wbr>TypeInitializationException' in ogr_csharp.dll <br>
An unhandled exception of type 'System.<wbr>TypeInitializationException' occurred in ogr_csharp.dll <br>
Additional information: The type initializer for 'OSGeo.OGR.OgrPINVOKE' threw an exception. <br>
<br>
The program '[2244] TestProj.vshost.exe' has exited with code 0 (0x0)</i></span><u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">______________________________<wbr>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/gdal-dev</a><u></u><u></u></p>
</div>
</blockquote>
</div>
</div>

</blockquote></div><br></div>