Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# and Java interoperability #766

Closed
DragonLi-Mi opened this issue Jul 24, 2017 · 13 comments
Closed

C# and Java interoperability #766

DragonLi-Mi opened this issue Jul 24, 2017 · 13 comments

Comments

@DragonLi-Mi
Copy link

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?

@davidfowl
Copy link
Member

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

@karelz
Copy link
Member

karelz commented Jul 24, 2017

Would IKVM.NET help? http://www.ikvm.net/

@DragonLi-Mi
Copy link
Author

@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?

@omajid
Copy link
Member

omajid commented Jul 24, 2017

The End of IKVM.NET

@DragonLi-Mi
Copy link
Author

It seems like I would have a really hard damn time.
@omajid

@dheijl
Copy link

dheijl commented Jul 25, 2017

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.

@commonsuppliz
Copy link

IKVM.NET seems to work only under full .net framework or mono. dotnetcore still missing some api to allow ikvm.net to run...

@DragonLi-Mi
Copy link
Author

Hi guys, I finally achieved this by using JNI to call c++ and use c++ to host a coreclr . It works.

@davidfowl
Copy link
Member

@heartlocker you should post a sample. I'm sure there are others that would appreciate it.

@DragonLi-Mi
Copy link
Author

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

@tvildo
Copy link

tvildo commented Oct 26, 2018

IKVM is alive
https://www.windwardstudios.com/blog/ikvm-is-alive-well
https://github.com/wwrd/ikvm8

@hackerhumble
Copy link

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

Can anyone pls tell me the steps to follow. What is MakeFile in CSharpCallJava Project? How to build and run it?

Thanks.

@mariomastrodicasa
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants