title: C# calling Java code loading unmanaged dll
body: <p>I'm working with some java code wich loads an unmanaged dll, just as the following:</p>
  
  <pre><code>public void Foo(){
      System.loadLibrary("absolute_path_to_my_dll.dll")
  }
  </code></pre>
  
  <p>It works fine from eclipse or console. </p>
  
  <p>Next step: I'm using IKVM tools to get a managed dll from my java app (ikvmc.exe). Everything works fine and my dll is built perfectly. In fact, I've imported that library in a Test Solution (and I've add all IKVM refereces needed -IKVM.Core.JDK, IKVM.Runtime.JNI, etc-). </p>
  
  <p>Well, here is the problem: when I run C# code the java call to System.loadLibrary(...) fails and I get an <strong>"UnsatisfiedLinkError: Can't load absolute_path_to_my_dll.dll"</strong>. Absolute path is ok and dll is there.</p>
  
  <p>Any help? Thanks in advance.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>I'll try to explain more in detail:</p>
  
  <p><strong><em>Java step</em></strong></p>
  
  <pre><code>public void Foo(){
      System.loadLibrary("absolute_path_to_my_dll.dll")
  }
  </code></pre>
  
  <p>If path is not correct this call gives the <strong>"UnsatisfiedLinkError"</strong> mentioned above. This is not the case, everything works well. The dll file is a 32 bit one, so I compiled this java project with jre7 x86 (in 64 bit mode loadLibrary call falis, obviously, saying we can't load 32 bit dll in 64 bit AMD machine).</p>
  
  <p><strong><em>Ikvm step</em></strong></p>
  
  <p>Now I compile java code in a managed dll wich can be imported in a .net project. First of all I export my java project to a jar file, "myJar.jar". Then i apply ikvmc.exe to generate a managed dll, let's say "myNewDll.dll".</p>
  
  <p>ikvm.exe -target:library -out:"myNewDll.dll" "myJar.jar"</p>
  
  <p>This step works nicely and i get a new dll I can import in my VS project.</p>
  
  <p><strong><em>C# step</em></strong></p>
  
  <p>Now I create a new VS tester solution. I add "myNewDll.dll" as reference so I can use it in my C# code. Also, I add IKVM.Core.JDK reference (if not, project can't compile) and configure project in 32 bit mode. Problems start here:</p>
  
  <ul>
  <li>Running this setup gives "IKVM.Runtime.JNI error". I've added that reference.</li>
  <li>Running again gives "can't find ikvm-native". As I can't add ikvm-native-win32-x86.dll or ikvm-native-win32-x64.dll as reference I put both of them in output path (bin/Debug).</li>
  <li>Next try it gives the "UnsatisfiedLinkError: Can't load xxx.dll".</li>
  </ul>
  
  <p>How can it be possible if that dll is loaded flawlessly in java step?</p>
  
  <p><strong><em>Annother try</em></strong></p>
  
  <p>Just before start crying I tried annother way: I created a java main program that only called Foo(). Then I generated an executable file with ikvmc.exe tool and called it in windows console. It gave me the same error, UnsatisfiedLinkError so maybe it's ikvmc.exe problem but I can't understand why. </p>
  
  <p>Any idea?</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Good news. It seems I've solved the problem. First of all, I had to <strong>add -platform:x86 to ikvmc.exe call</strong> (step 2). The dll generated was succesfully imported in my C# project and <strong>it works fine if we run in execution mode (NOT debugging)</strong>. If I try to debug in VS it gives me System.Runtime.InteropServices.SEHException. </p>
  
  <p>Is there any kind of bug related to debugging native code (dll loaded in java code) under native code (that java code loaded in C# using ikvm)? </p>