"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Can GoLang Applications Utilize C# DLLs?

Can GoLang Applications Utilize C# DLLs?

Published on 2025-01-16
Browse:932

Can GoLang Applications Utilize C# DLLs?

Can a DLL Made in C# Be Used in a GoLang Application?

While C# assemblies are not directly compatible with Go applications, there is a solution available through a project on GitHub: go-dotnet. This project provides functionality that enables the use of .NET assemblies from within Go programs.

Example of Usage:

package main

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

func main() {
    dll := dotnet.NewClrAssembly("MathForGo.dll")
    method := dll.GetMethod("Add")
    result, _ := method.Call(2, 3)
    fmt.Println(result)
}

In this example, the MathForGo.dll created in C# is loaded into the Go application using the NewClrAssembly function. The GetMethod function is then used to retrieve a reference to the "Add" method in the DLL. Finally, the Call function is invoked to call the method and obtain the result, which is then printed to the console.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3