0

I have a system, written in C# which is designed to be given a dll that contains a class implementing a certain interface, and then instantiate that class and invoke certain interface methods and use the responses.

The context is to build an AI Competition where people submit their AIs as C# dlls. And it all works perfectly. Yay!


Now I'd like to start supporting other languages, by the same approach.

Fundamentally users should upload a single file (and the metadata about what kind of file that is), and I then invoke the contents of that file accordingly.

For C#, that's "upload a dll" and "use C# System.Reflection to instantiate it to get a C# object implementing the interface, then just call the relevant methods".

I'm interested in knowing what other languages I can viably support? I could interact with anything that can compile down to an .exe and interact over the command line, or I could set up a Web API based interaction.

But what options are there for things that more directly resembling instantiating an object and interacting directly with that object?

  • It seems that Java can do this via IKVM
  • If I had a text file, or zip of files, that contained JS code, then could I invoke that in a C# environment somehow? (Note that this is running on a server - it's not a web page, so I can't trivially inject that JS into a webpage)
  • Scala? (Note that I know nothing whatsoever about Scala, other than that it is a Functional Language)
  • NodeJS? (Again, all I know is that Node is server-side JavaScript)
  • Others?

I'm very happy for answers to be a links to other SO questions that have solved this problem in specific languages - though I would like you to ensure that it is solving it in my particular context, of the user uploading a file (possibly a zip?) and me invoking that directly in a server-side C# enviroment.

Brondahl
  • 7,402
  • 5
  • 45
  • 74
  • Python? http://ironpython.net/ – Marco Feb 21 '18 at 11:56
  • You should perhaps check this link: https://en.wikipedia.org/wiki/List_of_CLI_languages – Marco Feb 21 '18 at 11:57
  • If you manage to compile all script languages that will be supported (javascript, python .. etc) to dll (c/c++ most probably) you can interact with them from c# (if thats the end goal) using pinkvoke and marshaling. Another alternative is the COM standard (which i think is more manegable in long term) – vasil oreshenski Feb 21 '18 at 13:28
  • Same way as IKVM does it. As long as it is written in a .NET compatible language with a compiler that generates an assembly then you can freely use it from C#. Practically all languages have a .NET compiler, albeit that such a compiler isn't always the first one the programmer might think of. – Hans Passant Feb 21 '18 at 13:41
  • FYI - [IKVM is no longer being supported](http://weblog.ikvm.net/). – NightOwl888 Feb 21 '18 at 17:33
  • For JavaScript/NodeJS, see https://github.com/tjanczuk/edge – hgcummings Feb 23 '18 at 07:59

1 Answers1

1

Is finding languages that will run within the CLR definitely the best approach here? There's not much consistency in how they all interface with C#, and you'd be doing extra work to support each language.

An alternative would be to spawn a separate, sandboxed, process, and interact via some well-defined interface (e.g. some agreed protocol using standard I/O streams, or TCP on a particular port or something). IIRC this is how the Google AI challenges worked in the past. This way, you don't have to specifically implement each language you need to support. People just need to provide an executable that meets your interface. Of course, you then have the different problem of safely sandboxing it, but this is still a generic problem rather than one that has to be solved on a per-language basis.

hgcummings
  • 1,043
  • 10
  • 19