8

Is there any way to execute a Go function from C#? For Python I would use Ironpython for example.

I know that I could spawn a process to execute a Go script, but I don't really want to fallback to such a solution, if possible.

A Google search didn't reveal anything, so is there any way to do that using an API? Or do I have to fallback on processes?

5
  • When you're invoking a process, you can read it's output in your C# code. There are probably numerous examples on SO. I'm not aware of any interop between Go and C#/the CLR though it wouldn't surprise me if there's one out there. Commented Jun 10, 2016 at 19:20
  • @evan Well, didn't know that. Thanks. But I'll still prefer an API though :) Commented Jun 10, 2016 at 19:20
  • Just based of a quick Google search I don't think you're going to be finding any API for Go - C# interop. Commented Jun 10, 2016 at 19:22
  • Can you use the Tardis Go Transpiler? tardisgo.github.io (Disclaimer: I have no Go experience) Commented Jun 10, 2016 at 19:26
  • @user2023861 yeah, I guess I could. Thanks Commented Jun 10, 2016 at 19:35

3 Answers 3

5

I think Frank's answer is not right! Golang supports many build mode, and one is c-shared mode, it means you can use it like a c module. e.g: https://www.trs.ai/c%E8%B0%83%E7%94%A8golang%E4%BB%A3%E7%A0%81/

Sign up to request clarification or add additional context in comments.

1 Comment

link is deprecated, this thread might help stackoverflow.com/questions/19431296/…
4

EDIT: my answer is now not true, since Go has been updated since I posted. this stackoverflow thread will help you solve your problem.

ORIGINAL ANSWER:

I don't think you're going to have much luck finding what you're looking for. Go is statically linked and C# doesn't support that.

From C#, calling a pre-compiled executable and reading the output is the easiest thing I can think of.

3 Comments

this question is not true anymore. go now can be dynamically build and can be called from languages like c, c++,c# etc..
@cahitbeyaz could you add some links how to run golang code with taking into account CLR security constrains?
@cahitbeyaz still can't find anything about it.
-1

you can use grpc implement calls
grpc works across languages and platforms

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.