How to call c# function from Erlang efficiently?

I want to call a c# function from Erlang and I’ve tried to use Erlang nodes written in c# to accomplish this but they are all outdated…

Here’s the one’s I’ve tried:

I’m looking for an alternative way to call a c# function (from a c# .NET application) from Erlang that doesn’t have insane overhead. I was starting a separate process every time to call the c# function, but the overhead is insane! If anyone has any other viable options let me know.

Have you tried re-using the C# program as a port and talk to it via stdin/stdout? Something like:

start() ->
  erlang:open_port({spawn,os:find_executable("csharp")},[]).

call(Port, Arg) ->
  true = port_command(Port, Arg),
  receive
    {Port,{data, Reply}} -> Reply
  end.

And then on the C# side you read from stdin and execute the function.

5 Likes

Strongly recommend that you don’t use it, but there’s always GitHub - robashton/erlang.net: Write your gen servers in VB.NET - hell why not?

I feel as though I’ve been summoned.

The link that Steve posts above is obviously an April Fool’s joke, but some of the code in there - specifically the type mapping, proxied calls, etc might be useful and aren’t an awful way to call into external code written in C# if you take the normal caveats to do with NIF functions written in C.

I doubt the project builds/runs/is useful as-is any more, but if you really need to invoke some existing C# code and you don’t want to wrap your C# app in a port… well it’s an option.

1 Like

Beetlejuice, Beetlejuice, Beetlejuice

1 Like

I’m just gonna use a C NIF from Erlang to call the C# function i think.

Thank you everyone

Wrap the C# function in a simple web app? Then you’re not paying for the start/stop overhead.

Back in the day, I’d have used NancyFx, but that’s been archived. I don’t know what the new hotness is. Kestrel, maybe?

To be fair, though, this is essentially just a port, but using HTTP for the communication, rather than stdin/stdout.

1 Like