Call .NET/C# code from Java

preview_player
Показать описание
Tutorial on how to call .NET/C# code from Java code.
It shows both using standard JNI and create a C++ proxy manually and also the use of JNI4Net.
Рекомендации по теме
Комментарии
Автор

Just what I was looking for to integrate some Java with C# - many thanks. (the music was fine :)

Minty
Автор

Okay, I have to say, this video was amazing! Thank you! I got everything working with JAVA 17. All runs smooth and great, like in the video. Thank you very much for the comments, they helped me correct some mistakes in advance. There were many nuances not described in the video, but they are all possible to solve. I have to say, all the DLL generated files have to be saved in the file where the java.exe file is, generally in the bin folder of the JDK version. And also, about minute 16:15, this command line worked for me:

-h . FromCSharp.java -d

where my class FromCSharp.java (where the java native method is) is in the *csharp directory.

Thank you so much for this video and God bless you! Regards from Russia! Sunday, November 11th, 2022.

robertoenriquechavezrodrig
Автор

In minute 16:15 is not clear at all from what directories what files we should paste the paths into the command. Could you please clarify this? You only say that we should run the command and that's all.

robertoenriquechavezrodrig
Автор

Very informative but the music was annoying.

achintyaroy
Автор

does this work under straight x64 systems? I dont want to mess around with 32->64 conversions

joelboardgamerpger
Автор

Thanks. Nice one. i was able to call an async method in C#.
Can u share how to bundle it as a standalone executable jar so that I won't have to worry about dependencies.

charlesokonkwo
Автор

Thanks for your video tutorial on jni4net and it helps me a lot.

RAJESHKUMAR-pymb
Автор

what to do if I need to call a helloWorld() method in C# that conatains Console.WriteLine("Hello World");
urgent help needed please.

bajwaAffan
Автор

Hi, can you say me where can I get that background sound ?

onurolce
Автор

Really helpful tutorial but my problem is how do I build the project based on the JNI if I am not allowed to move the C# dll anywhere else how do I build this Project

rajarshibanerjee
Автор

Thank you, really amazing video so helpful ...BUT THE MUSIC

zeppelindemarlina
Автор

Hi Thanks for a very useful post.
One thing only could please turn of the music in the backgoung!!!What was the point of having a background music?
Cheers
George

gekho
Автор

Hello, congratulations on the initiative.
I had a problem following the tuturial. When I try to run the project the following error is returned:

# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (0xe0434352), pid=12200,
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [KERNELBASE.dll+0x17788]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
#
#
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

Existe alguma relação desse erro com a edição do arquivo CppAuthenticator.h?
Não vi no vídeo como devo editar esse arquivo.

rricksena
Автор

Hi this is great... i am trying to upload test results to visual studio test case from a java program. can it be done ..if yes please post some examples on this

nishantchoudhary
Автор

but how to use in my Java Web Spring Applications.means i want to call my existing C# code in my Java Spring Web share me the process if u have

manassahu
Автор

//you need to add static keyword to the SharpAuthenticator and the method you are calling 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace  SharpAuthenticator
{
    public static class Authenticator  
    {
        public static bool Authenticate(String username, String password)
        {
            return username == "user" && password == "pass";
        }
    }
}

u
Автор

I get this error:Fatal error. (0x80004005): External component has thrown an exception.
at <Module>.authenticate(SByte*, SByte*)
at <Module>.Java_Authenticator_authenticate(JNIEnv_*, _jobject*, _jstring*, _jstring*)

wiiznokes
Автор

Use IKVM to convert the jar to a .net dll.

sporktheduck
Автор

If you had such:
Error 1 error C2352: : illegal call of non-static member 

What you need to do is add static method to SharpAuthenticator.cs:

public static Authenticator NewInstance()
{
     return new Authenticator();
}

then

change authentecate method in CppAuthenticator.cpp

{
auth =
return auth->Authenticate(toString(username), toString(password));
}

What have you did?
You create method, ehich execute constructor of class Authenticator.
Then you delegate it in CppAuthenticator.

ВиталийЛитвнов
Автор

After watching many times and checking all my code against yours, I still get an error in CppAuthenticator.cpp saying :
Error 1 error C2352: : illegal call of non-static member function

I can get rid of the error but it still does not work. Any suggestions? Did you make any changes you can share?

jeffgraham
visit shbcf.ru