zoukankan      html  css  js  c++  java
  • Cannot generate C# proxy dll with JNI4NET tool, running batch file as trusted assembly?

    From: https://stackoverflow.com/questions/41042368/cannot-generate-c-sharp-proxy-dll-with-jni4net-tool-running-batch-file-as-trust

    I am working on getting the tool JNI4NET working so that I can use some Java code I have within my C# application. As a simple initial test I have created a simple Java class library with a single class Person with one method public String GetName() { return "NoBody"; }. From here I have been following along with the samples given in the JNI download to edit the generateProxies.cmd to create the DLL wrapper of the jar.

    I didn't have much luck with this so I decided to try to perform the same action but with the sample, specifically the sample entitled myJavaDemoCalc. When executed generateProxies.cmd in the sample folder an error is thrown.

    (I will transcribe this picture if need be) 

    I have followed the link in the exception though while I somewhat understand what it means I am not sure if it is necessarily safe to enable loading from remote sources as it suggests at the end of the linked article.

    I am also confused why the exception is being thrown seeing that the generateProxies.cmd and thus ProxyGen.exe is being run from my C: drive.

    Anyone have an idea of what I could try next or know the issue here?

    For reference here is the generateProxies.cmd source from myJavaDemoCalc

    @echo off

    copy ....lib*.* work

    ....inproxygen.exe workmyJavaDemoCalc.jar -wd work

    cd work

    call build.cmd

    cd ..

    echo compiling usage

    csc.exe /nologo /warn:0 /reference:workjni4net.n-0.8.8.0.dll /reference:workmyJavaDemoCalc.j4n.dll /out:workdemo.exe /target:exe MyCalcUsageInDotnet.cs

    [Answer]

    I assume you downloaded that zip file and then immediately Extracted all files.

    However, because that zipfile did originate from an untrusted zone, being the internet, the files in it will also remain untrusted. It contains an alternate data stream with a zone identifier.

    When those assemblies get loaded by the framework, it checks if they can be trusted. Assemblies with that zone identfier still present don't get loaded. That is the exception you get:

    System.IO.FileLoadException: Could not load file or assembly 'file:///jni4net.n-0.8.8.0.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) --->
    System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch.

    The quickest solution to resolve this is to open the properties window of the downloaded zip file and tick unblock before you extract all files:

     

    If you already extracted all the files to a folder you can use the powershell command unblock-file

    Get-ChildItem -Path 'c:path	ofiles' -Recurse | Unblock-File

    But if you're sure that you will always run proxygen.exe with trusted assemblies, you can add the suggestion offered in the MSDN article by adding the loadFromRemoteSources element in the existing proxygen.exe.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
      </startup>
      <!-- trust all the thingz -->
      <runtime>
        <loadFromRemoteSources  enabled="true"/>
      </runtime>
    </configuration>
  • 相关阅读:
    图像裁剪功能,鼠标抬起移除事件,不只是想去掉鼠标抬起时的裁剪事件,重要的是jquery绑定的都是dom2级事件
    在 JavaScript 里 + 会把一些字符转化成数字
    ++[[]][+[]]+[+[]] == 10 //true
    node 接口
    windows下,node.js默认执行的根目录
    鸟速度不匀速的方法Math.sqrt(this.i++); 开根号
    rotate 里面的是弧度不是度,如果需要度则要转成度 Math.PI/180
    定义一个数,它可能为正 也可能为负 var num = Math.pow(-1,parseInt(Math.random() * 2) + 1);
    如何单独使用modelsim进行仿真
    Xilinx开发板信息
  • 原文地址:https://www.cnblogs.com/time-is-life/p/8985973.html
Copyright © 2011-2022 走看看