How to use Java in ASP.NET Core 3.1?



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 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!


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.

Answered By – Emre Utku Solak

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More