Initializing jni4net with .Net 4 x64

1,114 views
Skip to first unread message

wst

unread,
Feb 19, 2011, 5:14:04 AM2/19/11
to jni4net
Hi,

I have a problem to initialize Bridge using .Net 4 on Windows x64

My Environment is:
Windows Vista Business x64
.Net x64 2.0 and 4.0 installed

I tried the sample helloWorldFromJVM.

It works fine if I call
Bridge.init(new File("C:\\Java\\workspace\\NET-Java1\
\jni4net.n.w64.v20-0.8.2.0.dll"));

if I use Bridge.init() it tries to load jni4net.n.w64.v40-0.8.2.0.dll.
(This is what I want...)

But it fails with:
Can't initialize jni4net Bridge from C:\Java\workspace\NET-
Java1\jni4net.n.w64.v40-0.8.2.0.dll
Can't initialize jni4net BridgeCan't initialize jni4net Bridge.
Code:-1
Exception in thread "main" net.sf.jni4net.inj.INJException: Can't
initialize jni4net Bridge
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:56)
at net.sf.jni4net.Bridge.init(Bridge.java:46)
at Program.main(Program.java:40)
Caused by: net.sf.jni4net.inj.INJException: Can't initialize jni4net
Bridge. Code:-1
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:51)
... 2 more

Do you have any hint for me to get it run?

Many thanks in advance and best Regards,
Wolfgang

Pavel Šavara

unread,
Feb 19, 2011, 8:08:46 AM2/19/11
to jni...@googlegroups.com
Hi Wolfgang,

please try to download version next from here
http://pavel.savara.sweb.cz/files/jni4net-0.8.3.0-bin.zip

I improved error logging, so we may learn more about the issue.

Also please set verbosity on.
Bridge.setVerbose(true);
Bridge.init();

Thanks
Pavel

> --
> You received this message because you are subscribed to jni...@googlegroups.com
> http://groups.google.com/group/jni4net?hl=en-GB?hl=en-GB
> http://jni4net.sf.net/
>

wst

unread,
Feb 19, 2011, 8:29:09 AM2/19/11
to jni4net
Hello Pavel,

this ist the output:

Can't init BridgeExport:Es wurde versucht, eine Assembly von einer
Netzwerkadresse zu laden, was in früheren Versionen von .NET Framework
zum Ausführen der Assembly als Sandkastenassembly geführt hätte. In
dieser Version von .NET Framework wird die CAS-Richtlinie
standardmäßig nicht aktiviert, dieser Ladevorgang kann daher
gefährlich sein. Wenn Sie nicht beabsichtigen, durch diesen
Ladevorgang eine Sandkastenassembly zu erstellen, aktivieren Sie den
loadFromRemoteSources-Schalter. Weitere Informationen finden Sie unter
"http://go.microsoft.com/fwlink/?LinkId=155569".
Can't init BridgeExport:System.NotSupportedException: Es wurde
versucht, eine Assembly von einer Netzwerkadresse zu laden, was in
früheren Versionen von .NET Framework zum Ausführen der Assembly als
Sandkastenassembly geführt hätte. In dieser Version von .NET Framework
wird die CAS-Richtlinie standardmäßig nicht aktiviert, dieser
Ladevorgang kann daher gefährlich sein. Wenn Sie nicht beabsichtigen,
durch diesen Ladevorgang eine Sandkastenassembly zu erstellen,
aktivieren Sie den loadFromRemoteSources-Schalter. Weitere
Informationen finden Sie unter "http://go.microsoft.com/fwlink/?
LinkId=155569".
bei System.Reflection.RuntimeAssembly.nLoadFile(String path,
Evidence evidence)
bei System.Reflection.Assembly.LoadFile(String path)
bei net.sf.jni4net.BridgeExport.initDotNet(IntPtr envi, IntPtr
clazz)
Can't initialize jni4net Bridge from C:\Java\workspace\NET-
Java1\jni4net.n.w64.v40-0.8.3.0.dll
Can't initialize jni4net BridgeCan't initialize jni4net Bridge.
Code:-1
Exception in thread "main" net.sf.jni4net.inj.INJException: Can't
initialize jni4net Bridge
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:56)
at net.sf.jni4net.Bridge.init(Bridge.java:46)
at Program.main(Program.java:41)
Caused by: net.sf.jni4net.inj.INJException: Can't initialize jni4net
Bridge. Code:-1
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:51)
... 2 more

So it is a "sandbox" error. As far as I know (I'm a Java programmer,
not C#), the following entry has to be set in app.config:

<loadFromRemoteSources
enabled="true|false"/>

But where can I find the app.config for the dll to maniputlate it?

PS: my complete development environment including the dlls is on a
local computer.

Best Regards,
Wolfgang

On Feb 19, 2:08 pm, Pavel Šavara <pavel.sav...@gmail.com> wrote:
> Hi Wolfgang,
>
> please try to download version next from herehttp://pavel.savara.sweb.cz/files/jni4net-0.8.3.0-bin.zip
>
> I improved error logging, so we may learn more about the issue.
>
> Also please set verbosity on.
> Bridge.setVerbose(true);
> Bridge.init();
>
> Thanks
> Pavel
>

wst

unread,
Feb 19, 2011, 9:03:30 AM2/19/11
to jni4net
Hello Pavel,

thanks to the verbose output I found the solution.

It is enough to set all DLLs to "unblocked" in the file properties.

Now it runs very fine...

Best Regards and many thanks,
Wolfgang

Pavel Šavara

unread,
Feb 19, 2011, 3:35:14 PM2/19/11
to jni...@googlegroups.com, wst
Hi Wolfgang,

You probably unzipped the file with windows explorer, right ?

something like this ?
http://smartclientfactory.blogspot.com/2008/01/nmock2-was-blocked.html

There are couple of ways how I could address this problem
1) further improve error message
2) extend my troubleshooter page
3) distribute setup.exe instead of .zip file
4) detect the problem at runtime and delete alternate file stream
which contains the security information.

I don't like options 3) 4), so I 'll go with 1) and 2)

Thanks for your help!
Pavel

wst

unread,
Feb 19, 2011, 5:02:33 PM2/19/11
to jni4net
Hi Pavel,

I agree with you concerning options 1 and/or 2.
I only didn't know that unblocking is required. (I'm very new to .Net)

Best Regards,
Wolfgang

On Feb 19, 9:35 pm, Pavel Šavara <pavel.sav...@gmail.com> wrote:
> Hi Wolfgang,
>
> You probably unzipped the file with windows explorer, right ?
>
> something like this ?http://smartclientfactory.blogspot.com/2008/01/nmock2-was-blocked.html
> >http://jni4net.sf.net/- Hide quoted text -
>
> - Show quoted text -

Pavel Šavara

unread,
Feb 20, 2011, 5:18:20 AM2/20/11
to jni...@googlegroups.com, wst
That's not very .NET specific. It's rather windows specific 'idea'.
For example if you unzipped the package with anything else but windows
explorer, the security information would not be placed onto the dll's
alternate stream. The new thing is that CLR 4.0 handles that different
way.
BTW: The unblocking is new to me as well.

Cheers
Pavel

Reply all
Reply to author
Forward
0 new messages