Error in the webapp while connecting with JVM using jni4net from C#

mercury-01

I'm trying to access a simple java code from inside my C# webapp using jni4net, but it is throwing some errors.

Generated all proxies and dlls to access the java class.

I wrote the code for connecting with JVM inside the 'Program.cs' file.

Later on the custom java function ie. display_msg() is called from the testfunc() which can be called from anywhere inside the bot using Program.testfunc().

I'm attaching the Program.cs file and the exception occurring. Also I've named my java file as Test.java and it's inside package mypack.

Program.cs

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using net.sf.jni4net;
using System;
using mypack;

namespace ValidationBot
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var setup = new BridgeSetup();
            setup.Verbose = true;
            setup.AddAllJarsClassPath("./");
            Bridge.CreateJVM(setup);
            Bridge.RegisterAssembly(typeof(Test).Assembly);
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .ConfigureLogging((logging) =>
            {
                logging.AddDebug();
                logging.AddConsole();
            }).UseStartup<Startup>();

        public static void testfunc()
        {
            Test test = new Test();
            test.display_msg();

            Console.WriteLine("\nPress any key to quit.");
            Console.ReadKey();
        }

    }
}

Test.java

package mypack;
import java.io.*;

public class Test
{
  public static void main(String args[])
  {
     int s =10;
     System.out.println(s);
  }
  public void display_msg()
  {
     System.out.println("Hello, I'm inside a java program");
  }
}

Exception

Exception thrown: 'System.MissingMethodException' in jni4net.n-0.8.8.0.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in System.Private.CoreLib.dll
Exception thrown: 'System.TypeInitializationException' in jni4net.n-0.8.8.0.dll
An unhandled exception of type 'System.TypeInitializationException' occurred in jni4net.n-0.8.8.0.dll
The type initializer for 'net.sf.jni4net.utils.Registry' threw an exception.

I'm a beginner to C# so please help me out with this.

Botje

From the comments we deduced that .NET core 2.1 does not support this method: (and maybe others)

System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error while calling C# from java using jni4net from 64 bit Os

From Dev

Getting error while connecting SSH using python

From Dev

Error while connecting to PayPal using REST API

From Dev

Error while connecting to postgresql using sqlalchemy

From Dev

Connecting to Oracle database using powershell script. Error while connecting

From Dev

Error while connecting to SQL Server from pyspark

From Dev

Error while connecting postgres db from airflow

From Dev

Error while connecting Ubuntu server from a client

From Java

UnsatisfiedLinkError exception while working with dll and java jni4net

From Dev

Error while connecting to SQL server using pyodbc from Azure Synapse Notebook

From Dev

Error connecting to SSL server using C# and .NET 4.5

From Dev

Unknown error while connecting

From Dev

Login Authentication error while connecting to SQL Server using ASP.NET MVC

From Dev

error while connecting to hp Quality Center using com4j

From Dev

Unauthorized error while connecting Object Storage from API from Postman

From Dev

Firebase Storage CORS error while uploading file from Vue webapp

From Java

Error Connecting to Solr using Solrj from Java

From Dev

Error, While Connecting To Mlabs Using Node.js

From

Handling error while connecting to kubernetes server using config file

From Dev

Internal server error while connecting to Server in android using volley?

From Dev

Ignite Client crashes JVM while Connecting to cluster

From Java

Error while connecting to AWS SQS from spring boot

From Dev

Authentication error while connecting to MongoDB from remote host

From Dev

Azure - Error while connecting to VSTS from Deployment Source

From Dev

Error while connecting to AWS EMR cluster from mac

From Dev

Error while connecting from Remix via rpc to local blockchain

From Dev

Error while connecting to AKS via Azure Cli from PowerShell

From Dev

Error while connecting android app to get string from mysql to a listview

From Dev

How to prevent my JNI C code from exiting while the JVM it launched is still running a Java thread?

Related Related

  1. 1

    Error while calling C# from java using jni4net from 64 bit Os

  2. 2

    Getting error while connecting SSH using python

  3. 3

    Error while connecting to PayPal using REST API

  4. 4

    Error while connecting to postgresql using sqlalchemy

  5. 5

    Connecting to Oracle database using powershell script. Error while connecting

  6. 6

    Error while connecting to SQL Server from pyspark

  7. 7

    Error while connecting postgres db from airflow

  8. 8

    Error while connecting Ubuntu server from a client

  9. 9

    UnsatisfiedLinkError exception while working with dll and java jni4net

  10. 10

    Error while connecting to SQL server using pyodbc from Azure Synapse Notebook

  11. 11

    Error connecting to SSL server using C# and .NET 4.5

  12. 12

    Unknown error while connecting

  13. 13

    Login Authentication error while connecting to SQL Server using ASP.NET MVC

  14. 14

    error while connecting to hp Quality Center using com4j

  15. 15

    Unauthorized error while connecting Object Storage from API from Postman

  16. 16

    Firebase Storage CORS error while uploading file from Vue webapp

  17. 17

    Error Connecting to Solr using Solrj from Java

  18. 18

    Error, While Connecting To Mlabs Using Node.js

  19. 19

    Handling error while connecting to kubernetes server using config file

  20. 20

    Internal server error while connecting to Server in android using volley?

  21. 21

    Ignite Client crashes JVM while Connecting to cluster

  22. 22

    Error while connecting to AWS SQS from spring boot

  23. 23

    Authentication error while connecting to MongoDB from remote host

  24. 24

    Azure - Error while connecting to VSTS from Deployment Source

  25. 25

    Error while connecting to AWS EMR cluster from mac

  26. 26

    Error while connecting from Remix via rpc to local blockchain

  27. 27

    Error while connecting to AKS via Azure Cli from PowerShell

  28. 28

    Error while connecting android app to get string from mysql to a listview

  29. 29

    How to prevent my JNI C code from exiting while the JVM it launched is still running a Java thread?

HotTag

Archive