I want to call java method in c# code and also invoke c# dll in java code.
The environment is Ubuntu 16.10 x64. The c# code is build in .net core 2.0 p1.
Which is the best way to implement?
I try to use c++ as a wrapper. Is the .net core lack of managed c?
I believe the only way to do this today would be to use C/C++ as a bridge between the 2 languages. Also be careful as you need to make sure GC references are tracked between the 2 runtimes (if you pass GC handles back and forth). I believe Xamarin Android does this today but I don't know the details.
@migueldeicaza this seems up your alley?
/cc @jkotas for ideas
Would IKVM.NET help? http://www.ikvm.net/
@karelz IKVM.NET is base on Mono and the .NET Framework. Is it possible for me to use it between java and .net core lib? Or you mean that I can do a migration job to change IKVM to.net Core?
It seems like I would have a really hard damn time.
@omajid
It's quite easy calling Java using Pinvoke and a plain C-wrapper as a go-between that uses JNI to load the JVM and to expose functions that call into Java using JNI. You would have to deal with the restrictions of the JNI though (data types). I've done this in Delphi to call Java. Perhaps there are better possibilities than JNI nowadays, as I haven't used Java for many years. Calling a C# dll from Java could be done using "unmanaged exports" (nuget) to expose c# as a plain C or COMM interface.
IKVM.NET seems to work only under full .net framework or mono. dotnetcore still missing some api to allow ikvm.net to run...
Hi guys, I finally achieved this by using JNI to call c++ and use c++ to host a coreclr . It works.
@heartlocker you should post a sample. I'm sure there are others that would appreciate it.
The basic code for core CLR host;
https://github.com/dotnet/coreclr/tree/master/src/coreclr/hosts/unixcoreruncommon
For Java invoke C#:
https://github.com/heartlocker/JavaCallCSharp
For C# invoke Java:
https://github.com/heartlocker/CSharpCallJava
The basic code for core CLR host;
https://github.com/dotnet/coreclr/tree/master/src/coreclr/hosts/unixcoreruncommonFor Java invoke C#:
https://github.com/heartlocker/JavaCallCSharpFor C# invoke Java:
https://github.com/heartlocker/CSharpCallJava
Can anyone pls tell me the steps to follow. What is MakeFile in CSharpCallJava Project? How to build and run it?
Thanks.
I want to bring your attention on the project JCOReflector.
The project follows another approach to create the interoparability from JVM (not only Java) to .NET (not only C#): the tool creates Java classes which exposes .NET classes (Framework/Core/5) in a Java fashion.
On opposite, execute JVM (Java) code from .NET (C#) is very simple thanks to the dynamic feature of .NET: see ConsoleTest or https://www.jcobridge.com/net-examples/dotnet-examples/ to clarify the concept.
Most helpful comment
IKVM is alive
https://www.windwardstudios.com/blog/ikvm-is-alive-well
https://github.com/wwrd/ikvm8