1

I have created a C# project(dll) that I need to call from java. The C# project has dependendecies (dlls) that were compiled using c2.0 of .net. The machine am using has been installed with .net 4.5. I am compiling the C# project using .net 3.0 and generates the dll. I am using jni4net to call the C# dll (functions) in java but I keep on getting this error. "System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

Here is my java code.

Bridge.setVerbose(false);
 Bridge.init();
           Bridge.setClrVersion("v20");
                Bridge.LoadAndRegisterAssemblyFrom(new File(""));//path to the .net dll generated using proxygen.exe
             Bridge.setVerbose(true);

My Question is Can I load the App.config from java or is there a way in windows or within java to enable the program pick .net 3.5?

NemugaM
  • 11
  • 5
  • Never encountered your issue, as I have not used jni4net *yet*. Still, it feels like your problem can be fixed if you follow the advices on [this post](http://stackoverflow.com/questions/3179028/mixed-mode-assembly-in-net-4). In order to add an app config file, just create a `XXX.config` file in the same folder as your assembly. The `XXX` part is the name of your exe/dll without the file extension. I am not sure if it will work for .dll without having extra C# code to load the configuration, but it should work for an .exe – Ivaylo Slavov Nov 30 '15 at 07:08
  • @IvayloSlavov I have tried putting the App.config in the same directory but it still doesnt work for the dll – NemugaM Nov 30 '15 at 07:17
  • Please, note that the .NET application will not look for an `App.config` file automatically, rather for a `XXX.config` where `XXX` is the application assembly name. For example `Test.exe` should have a `Test.exe.config` in order to be picked up automatically. – Ivaylo Slavov Nov 30 '15 at 07:19
  • but in my case its a dll not a exe – NemugaM Nov 30 '15 at 07:23
  • How can I do that from java ? – NemugaM Nov 30 '15 at 07:23
  • Not really sure. What I see as a potential problem with your code is this line `Bridge.setClrVersion("v20")`. Why don't you set the version to 3.5 or 4.0? Even if the dll is compilable with v2.0, it might not run becase you used a .NET compiler of higher version (without explicitly compiling with 2.0 compatibitlity). This could explain your error. – Ivaylo Slavov Nov 30 '15 at 07:26
  • @IvayloSlavov have alsoe tried this Bridge.setClrVersion("4.5") and it stills doesnt work! I get same error – NemugaM Nov 30 '15 at 07:34

0 Answers0