Core: How to generate .so file from dotnet core classlib instead of .dll

Created on 20 Nov 2019  路  5Comments  路  Source: dotnet/core

How to generate .so file from dotnet core classlib instead of .dll

I have developed one dotnet core classlib project and i can successfully use its .dll in linux machine. now, i have to generate .so from dotnet core classlib as i want to share it to our team as native shared object instead of .dll

General

Recently i developed one classlib project in dotnet core v3.0 using VS2019. the main objective of this .dll is to allow the client application to communicate with external device via COM/Serial port and TCP/IP. the main thing is it should work on linux machine.

its 100% worked as i did it with latest dotnet core v3.0 and the client application too developed using dotnet core v3.0.

now, my problem is, i need to consume the functionalities from that dotnet core C# .dll from another one Java based application. i can't develop the same in java to share it as .jar with that java client application and its time consuming too.

i can import the .so lib format in java, if i able to compile my dotnet core classlib project into .so format, it will be great save for me. i searched on the internet, unable to get proper solution for this.

some blogs/posts telling that i can create .so only from C/C++ .

kindly advise me in this and how to generate the .so file from dotnet core v3.0 classlib project.

Env Details

OS: ubuntu 16.04 and ubuntu 18.04
IDE: VS2019 Community Edition
Version: Dotnet core V3.0 latest
Project type: Console and Classlib proects

Most helpful comment

.NET Core provides a hosting layer to enable running .NET from any other language. Here are some relevant samples: https://github.com/dotnet/samples/tree/master/core/hosting

Using a c-style interop layer is the recommended way to achieve what you are looking for.

All 5 comments

Hi,
Anyone answer please!

The '.so' extension should be used for native libraries (such as ones built from C or C++), not for .NET assemblies. We do not yet have a method to generate native libraries in this way -- a process attempting to load a .NET assembly would fail, as it requires the .NET host to run it. The standard extension for .NET assemblies is ".dll".

An easy solution might be to wrap your library in an ASP.NET Core or gRPC API, and call it from Java through that.

A hard solution might be to run the .NET host directly from Java interop, but I am not sure if we expose C APIs necessary for that. @jeffschwMSFT @livarcocc do you know?

.NET Core provides a hosting layer to enable running .NET from any other language. Here are some relevant samples: https://github.com/dotnet/samples/tree/master/core/hosting

Using a c-style interop layer is the recommended way to achieve what you are looking for.

Thank you @jeffschwMSFT , i will give a try to your suggested way. anyway it would be great if .NET Core allows us to generate .so file by default.

Looks like this was answered; closing out.

Was this page helpful?
0 / 5 - 0 ratings