• Stars
    star
    456
  • Rank 95,985 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go wrapper for the .NET Core Runtime.

go-dotnet

GoDoc MIT License Build status

This is a PoC Go wrapper for the .NET Core Runtime, this project uses cgo and has been tested under OSX. It covers two basic use cases provided by the CLR Hosting API:

  • Load and run an .exe, using its default entrypoint, just like corerun and coreconsole do, check ExecuteManagedAssembly.

  • Load a .dll, setup delegates and call them from your Go functions.

I've tried calling both C# and VB.NET methods, of course you need to generate the assembly first, check below for more details!

Note: After some tweaks it seems to work fine under Linux! Remember to install the SDK first :)

Capture

An example

package main

import (
	"github.com/matiasinsaurralde/go-dotnet"

	"fmt"
	"os"
)

func main() {
	fmt.Println("Hi, I'll initialize the .NET runtime.")

	/*
		If you don't set the TRUSTED_PLATFORM_ASSEMBLIES, it will use the default tpaList value.
		APP_PATHS & NATIVE_DLL_SEARCH_DIRECTORIES use the path of the current program,
		this makes it easier to load an assembly, just put the DLL in the same folder as your Go binary!
		You're free to override them to fit your needs.
	*/

	properties := map[string]string{
		// "TRUSTED_PLATFORM_ASSEMBLIES": "/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/mscorlib.ni.dll:/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Private.CoreLib.ni.dll",
		// "APP_PATHS":                     "/Users/matias/dev/dotnet/lib/HelloWorld",
		// "NATIVE_DLL_SEARCH_DIRECTORIES": "/Users/matias/dev/dotnet/lib/HelloWorld",
	}

	/*
		CLRFilesAbsolutePath sets the SDK path.
		In case you don't set this parameter, this package will try to find the SDK using a list of common paths.
		It seems to find the right paths under Linux & OSX, feel free to override this setting (like the commented line).
	*/

	runtime, err := dotnet.NewRuntime(dotnet.RuntimeParams{
		Properties:                  properties,
		// CLRFilesAbsolutePath: "/usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0"
	})
	defer runtime.Shutdown()

	if err != nil {
		fmt.Println("Something bad happened! :(")
		os.Exit(1)
	}

	fmt.Println("Runtime loaded.")

	SayHello := runtime.CreateDelegate("HelloWorld", "HelloWorld.HelloWorld", "Hello")

    // this will call HelloWorld.HelloWorld.Hello :)
	SayHello()
}

Preparing your code (C#)

I've used dmcs (from Mono) to generate an assembly file, the original code was something like:

using System;

namespace HelloWorld {

	public class HelloWorld {
    	public static void Hello() {
      		Console.WriteLine("Hello from .NET");
    	}
	}

}

And the command:

dmcs -t:library HelloWorld.cs

Preparing your code (VisualBasic)

I did a quick test with this program, using the VB.NET compiler from Mono:

vbnc -t:library HelloWorld.vb

I'm not sure about the status of Roslyn but it could be interesting to try it.

Setup

Coming soon!

Ideas

  • Run some benchmarks.
  • Add/enhance net/http samples, like this.
  • Provide useful callbacks.
  • Support blittable types.
  • CSharpScript support.
  • Code generation tool (with go generate), a few notes here.
  • Add tests.

I'm open to PRs, Go/.NET swag, suggestions, etc.

Additional resources

Build Status

Linux x64 / Go 1.9/1.10 / .NET Core 1.0/2.0 - OS X / Go 1.9/1.10 - .NET Core 1.0/2.0

Linux and OS X build status

Windows / Go 1.9 / .NET Core 2.x

Windows build status

License

MIT

More Repositories

1

facebook-tunnel

Tunneling Internet traffic over Facebook chat.
Roff
1,288
star
2

transports

A HTTP proxy that aims to support different transports.
Go
105
star
3

evilredis

Script for doing evil stuff to Redis servers (for educational purposes only).
JavaScript
71
star
4

go-wasm3

Golang wrapper for WASM3 (https://github.com/wasm3/wasm3)
C
63
star
5

rust-v8worker2

Minimal Rust binding to V8 (based on ry/libv8worker2)
C++
34
star
6

wikipedia

Tool for extracting plain text from wikipedia data
Ruby
30
star
7

cgo-channels

A quick program to explore the idea of sending data to a Go channel from C.
Go
30
star
8

language

Experiments with letter frequencies, n-grams and language detection.
Ruby
22
star
9

go-web-shell

Simple web shell (+web server). Got it running on a rooted Android (checkout Makefile for ARM settings).
Go
22
star
10

scraper-supermercados

Pequeño programa para realizar scraping de precios de supermercados de Paraguay.
Go
20
star
11

etherforum

An experimental / proof of concept / distributed forum built on top of Ethereum
JavaScript
14
star
12

dbscan

DBSCAN implementation (forked from shiguodong/dbscan)
Ruby
13
star
13

go-mcu

Alternative CLI tool and Go package for NodeMCU-based modules.
Go
11
star
14

wasm-libxml2

A quick experiment to build and run libxml2 as a WebAssembly module.
C
10
star
15

go-wavm

Experimental Golang wrapper for WAVM
Go
10
star
16

aqmap

Go
9
star
17

sl

Intérprete experimental de SL, basado en Go.
Go
9
star
18

ng-soundslice

Simple module to integrate Soundslice (interactive music scores) with AngularJS.
JavaScript
9
star
19

node-deepgram

NodeJS wrapper for Deepgram
JavaScript
7
star
20

loudp2p

Experimental peer to peer network for music streaming.
Go
6
star
21

go-wasm-benchmark

A very simple benchmark to try out WASM VMs in Go
Go
5
star
22

leap-hakembo

rock-paper-scissors / yan ken po / hakembo & leap motion
JavaScript
5
star
23

go-dbscan

Some implementation of DBSCAN
Go
5
star
24

ng-chunked-audio

ngAudio-like for audio chunks, using MediaSource.
JavaScript
5
star
25

go-lua-benchmark

Comparing the performance of LuaJIT embedded in Go.
Go
4
star
26

dlpython

Dynamic Python bindings for Golang
Go
4
star
27

binarypatch

Storing & retrieving arbitrary data from program headers
Go
4
star
28

yowsup-http-wrapper

Very simple HTTP wrapper for Yowsup Whatsapp Client
Python
4
star
29

dailychanges

Tool for scraping Dailychanges (nameserver & domain activity).
Ruby
4
star
30

router-fingerprint

Tool for matching a router's vendor/model.
Ruby
4
star
31

tizen-socketio-client

First experiment with Tizen - Socket.IO based chat (client)
CSS
3
star
32

stp-dataset

Dataset of science and technology parks
HTML
3
star
33

letsencrypt-stunnel-java

A simple experiment with Let's Encrypt + stunnel + Java
Java
3
star
34

sfnt2woff

Fork of Jonathan Kew's sfnt2woff
C
3
star
35

gender-detection

Playing with the OpenCV Local Binary Patterns Histograms (LBPH) class
3
star
36

redis-dfs

Redis Distributed FS PoC
JavaScript
2
star
37

dartchat

experimental chat using dart, websockets & redis (pub/sub)
Dart
2
star
38

vericast-ifpi

Vericast is a global music identification service that monitors millons of songs over 3000 radios and televisions across more than 60 countries worldwide.
Ruby
2
star
39

mandioca

Experimental API gateway written in Elixir.
Elixir
2
star
40

tizen-socketio-server

First experiment with Tizen - Socket.IO based chat (server)
JavaScript
2
star
41

geth-watcher

A very simple Ethereum block watcher
JavaScript
2
star
42

apbp

Another PHP Blog's Planetarium.
PHP
2
star
43

nicpy

Ruby
2
star
44

gce-test-app

Testing out Google Compute Engine
JavaScript
2
star
45

dropbox-autopost

This Wordpress plugin allows you to post files/directories from your Dropbox.
PHP
2
star
46

ircbot

experimental/containerized irc bot
JavaScript
2
star
47

evilfizzbuzz

Go
2
star
48

elance-wr-bug

Elance: details about security issue.
Ruby
2
star
49

sonork

C++
2
star
50

cp-test-suite

Go
2
star
51

bytes2wav

Quick experiment on storing arbitrary data in a WAV file.
Go
1
star
52

batik

simple wrapper for batik's svg rasterizer
Ruby
1
star
53

opc

Open proxy crawler
Go
1
star
54

battlehack-boston-bets

Bets during BattleHack Boston
CSS
1
star
55

go-language

I didn't want to write the classic Hello World program.
Go
1
star
56

gemdeps

visualizing gem dependencies
1
star
57

protobuf-experiment

My experiment with Protobuf, Brotli, JSON & base64
Go
1
star
58

golang.nanorc

taken from cat-v dot org
1
star
59

sgb6580

Motorola SGB6580 PoC
C
1
star
60

redis-crawler

Tool for finding open Redis instances
1
star
61

seamus

RC Car / Arduino Experiment
Arduino
1
star
62

workshop

Go
1
star
63

ng-electron

Easy AngularJS-Electron integration
JavaScript
1
star
64

angelco

Scraping angel.co
Ruby
1
star
65

kurtural-heading-buttons

Custom heading buttons
JavaScript
1
star
66

products-services

Go
1
star
67

alpine-wrk2

wrk2 package for Alpine Linux
1
star
68

go-mcu-bridge

1
star
69

deno-playground

TypeScript
1
star
70

tsje

Utilidad para extraer información del padrón electoral.
Ruby
1
star
71

tyk-sample-app

Sample app for Tyk CF deployment.
Go
1
star
72

alpine-php-amqp

PHP-AMQP extension package for Alpine Linux
1
star
73

fbooks

Mining book data from FB
Ruby
1
star
74

runc-nvidia-test

1
star
75

opendbf

Free & open DBF viewer
1
star
76

streetmusic

Ruby
1
star
77

deezer-lookup

Deezer is a web-based music streaming service. This gem allows you to lookup song/artist info using Deezer API (it uses levenshtein for better matching, the thresholds are configurable).
Ruby
1
star
78

crawler

1
star
79

nim2go

An experimental transpiler for Nim, targeting Go and the Go compiler.
Go
1
star
80

redisjs

RedisJS is a loadable module that lets you interact with Javascript (and the Node.js ecosystem) from Redis.
C
1
star
81

bench

Go
1
star
82

alpine-librabbitmq

librabbitmq package for Alpine Linux
1
star
83

grpc-ipc

An IPC-oriented gateway based on gRPC and Protocol Buffers.
Go
1
star
84

mandioca-dashboard

JavaScript
1
star
85

dispatcher-benchmark

Go
1
star
86

conductortestapp

Python
1
star
87

delicious-experiments

Playing out with del.icio.us to find more about me
Ruby
1
star