如何处理混合模式程序集是针对jni4net中的版本v2.0.50727错误构建的

时间:2015-11-26 11:59:12

标签: java c# .net

我创建了一个具有依赖项(dll)的C#dll项目。我正在成功编译C#dll并使用jni4net生成我需要在java中使用的dll和jar文件。 jar文件和dll成功生成,但是当我运行java代码时,我收到此错误。 “混合模式程序集是针对运行时版本v2.0.50727构建的,如果没有其他配置信息,则无法在4.0运行时加载。”我的问题是如何在proxygen.exe中包含App.config文件来解决此错误。我在C#项目中的app.config文件是

<?xml version="1.0" encoding="utf-8" ?>

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup> 
</configuration>

我需要从proxygen.exe生成的dll来读取配置文件。 这是我的java代码

Bridge.setVerbose(false);
                Bridge.setDebug(true);
                Bridge.init();

                Bridge.LoadAndRegisterAssemblyFrom(new File(""));//path to the generated dll from proxygen.exe

                CsharpClass op=new CsharpClass();

1 个答案:

答案 0 :(得分:0)

在Java中添加Bridge.setClrVersion(“v20”);

或者您需要将C#编译器设置为针对.NET 4.0进行编译

另见 https://github.com/jni4net/jni4net/blob/master/content/samples/runtimeSelection/

相关问题