skip to Main Content

I’m building a REST API with ASP.NET, which should ideally be able to use Java code. I’ve already managed to create a bridge between .NET and Java by using jni4net in a simple console application. This is absolutely necessary due the non-existing interoperability of .NET and Java.

Nevertheless I can’t create a bridge in my ASP.NET project by using jni4net. Apparently this is a common error due the fact that .NET core 2.1 or later versions do not support the methods shown below. I am refering to this question: "Error in the webapp while connecting with JVM using jni4net from C#".

MissingMethodException: Method not found: ‘System.Reflection.Emit.AssemblyBuilder System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)’.

Note that I’m using .NET core 3.1 for my ASP.NET project and jni4net 0.8.8.0. Anyways I’m would change my .NET version if needed. My current implementation in Program.cs looks like this:

using net.sf.jni4net;

public class Program
{
    public static void Main(string[] args)
    {
        var setup = new BridgeSetup();
        setup.Verbose = true;
        Bridge.CreateJVM(setup); // Error is thrown here
    }
}

Does anybody know if there is a way to bypass this error OR how to use Java code in an ASP.NET project? I highly appreciate any help or suggestion, sheers!

2

Answers


  1. As far as I know jni4net is not compatible with .NET Core. It’s for .NET Framework.

    This is absolutely necessary due the non-existing interoperability of .NET and Java.
    I don’t know the circumstances but it shouldn’t be a necessity. Just build a service that exposes API to C# code. Voila you have a bridge. Or you can use CORBA however it’s so complex it doesn’t worth at all imo.

    Login or Signup to reply.
  2. An API is a medium that recieves requests from client, processes those requests inside and responds back to the client.

    You can probably do what you want to do by creating an API on .NET Core and consume that API in your Java project.

    In the simplest way, you can create an API endpoint in your .NET project’s controller and send a request to that api on your Java application using the target URL of your API endpoint.
    The response from your API is going to be in JSON format.

    Please note that you can consume an API regardless of the language since the communication between your application and your API is going to be via HTTP requests and JSON responses.

    Some useful video links to start with:

    I also would like to clarify that HTTP is just a a protocol. You can probably achieve what you want with other communication protocols as well but this one is fairly more popular and suitable for your needs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search