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

..\..\bin\proxygen.exe work\myJavaDemoCalc.jar -wd work

cd work

call build.cmd

cd ..

echo compiling usage

csc.exe /nologo /warn:0 /reference:work\jni4net.n-0.8.8.0.dll /reference:work\myJavaDemoCalc.j4n.dll /out:work\demo.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\to\files' -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>

Cannot generate C# proxy dll with JNI4NET tool, running batch file as trusted assembly?的更多相关文章

  1. unity3d MonoDevelop引用外部自定义dll文件报错:are you missing an assembly reference?

    在unity3d 编辑器 MonoDevelop 中引用外部自定义dll文件报错:are you missing an assembly reference? 因为unity还停留在.NET Fram ...

  2. COM模块三---根的形成和注册代理server(Building and Registering a Proxy DLL)

    Prerequisite:C++ 程序员,熟windows计划,熟Win32 Dll,了解windows注册表. 笔者:割者 上一篇文章中,我们定义了COM接口.通过编译生成了四个文件,本文使用这四个 ...

  3. Jenkins + Github持续集成构建Docker容器,维基百科&人工自能(AI)模块

    本文分两部分,第一部分是手动计划任务的方式构建Github上的Docker程序,第二部分是用Github webhook Trigger一个自动构建任务. Jenkins采用2.5版本Docker采用 ...

  4. Assembly.LoadFrom加载程序集无法释放资源的解决方案

    下面此方法加载程序集会导致程序集一直被占用 Assembly asm = Assembly.LoadFrom(dllPath); 解决方案: //通过此方法读取可以解决dll被占用问题 byte[] ...

  5. Scott Hanselman's 2014 Ultimate Developer and Power Users Tool List for Windows -摘自网络

    Everyone collects utilities, and most folks have a list of a few that they feel are indispensable.  ...

  6. Learning WCF Chapter1 Generating a Service and Client Proxy

    In the previous lab,you created a service and client from scratch without leveraging the tools avail ...

  7. jni4net使用小结

    网站首页 http://jni4net.com/ 一个简单的例子: 1)      从这里下载binaries,然后解压缩. https://sourceforge.net/projects/jni4 ...

  8. [转]Replace all UUIDs in an ATL COM DLL.

    1. Introduction. 1.1 Recently, a friend asked me for advise on a very unusual requirement. 1.2 He ne ...

  9. DYNAMIC LINK LIBRARY - DLL

    https://www.tenouk.com/ModuleBB.html MODULE BB DYNAMIC LINK LIBRARY - DLL Part 1: STORY What do we h ...

随机推荐

  1. C++ code:剩余串排列

    方法一: 一种直观的解是,先对第一个字串排序,然后逐个字符在第二个字串中搜索,把搜索不到的字符输出,就是所要的结果. 然而,算法库中有一个集合差运算set_difference,而且要求两个集合容器是 ...

  2. 微信h5支付源码DEMO参考

    类库代码 wechatH5Pay.php <?php //use Flight; /** * 微信支付服务器端下单 * 微信APP支付文档地址: https://pay.weixin.qq.co ...

  3. django中,如何把所有models模型文件放在同一个app目录下?

    django的每个app目录下,都有自己的models.py文件. 原则上,每个app涉及的数据库,都会定义在这个文件里. 但是,有的数据库,涉及到多个app应用,不是很方便放在一个单独的app里. ...

  4. [转] webpack3.0踩坑:postcss-loader的使用

    解决方案: 只是换了一种引入方式,解决了 1,创建postcss.config.js文件,添加如下代码:(引入autoprefixer插件)   1 2 3 4 module.exports = {  ...

  5. xpath-helper: 谷歌浏览器安装xpath helper 插件

    1.下载文件xpath-helper.crx xpath链接:https://pan.baidu.com/s/1dFgzBSd 密码:zwvb,感谢这位网友,我从这拿到了 2.在Google浏览器里边 ...

  6. hdu1873 看病要排队【优先队列】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 看病要排队 Time Limit: 3000/1000 MS (Java/Others)     ...

  7. P3917 异或序列

    P3917 异或序列暴力前缀异或枚举每一个区间,再求和,60分.正解:按每一位来做对于区间[l,r],如果它对答案有贡献,区间中1的个数一定是奇数,可以按每一位取(1<<i)的前缀和,q[ ...

  8. MySQL 5.7.14 net start mysql 服务无法启动

    解决方法: 1.mysqld  --initialize 初始化data目录 2.重新输入net start mysql命令 补充,服务停止的方法:net stop mysql

  9. Java并发编程快速学习

    上周的面试中,被问及了几个关于Java并发编程的问题,自己回答的都不是很系统和全面,可以说是"头皮发麻",哈哈.因此果断购入<Java并发编程的艺术>一书,学习后的体会 ...

  10. Python + Selenium操作一:截图详解

    在做测试的时候,空口无凭都是白掐,特别是自动化测试的时候,更需要图片来佐证自己发现的问题 话不多说,直接进入主题,技术就是这么直白 Webdriver自带截图功能,get_screenshot_as_ ...