All Products
Search
Document Center

Machine Translation:.NET SDK

Last Updated:Apr 01, 2026

The Machine Translation .NET SDK lets you integrate Alibaba Cloud machine translation into Windows applications. It supports .NET Framework 3.5, 4.0, and 4.5. All versions share the same interfaces and functions, though the SDK files differ per .NET Framework version.

Prerequisites

Before you begin, ensure that you have:

  • An Alibaba Cloud account with real-name verification completed

  • An AccessKey ID and AccessKey secret (obtain them from the AccessKey Management page; the AccessKey must be enabled)

  • .NET Framework 3.5, 4.0, or 4.5 installed

  • Visual Studio 2010 or later

  • The Alibaba Cloud .NET SDK installed.NET SDK

Install the SDK

Install the Machine Translation .NET SDK using NuGet:

dotnet add package aliyun-net-sdk-ros-version 2.2.8
dotnet add package aliyun-net-sdk-alimt
If you open the project in Visual Studio 2017, unload the feature test project in the solution before proceeding. Do not compile from source.

The SDK source is also available on GitHub.NET SDK.

Make your first translation request

The following example translates the English word "Hello" into Chinese using the TranslateGeneralRequest API.

The TranslateGeneralResponse object contains a Data field with the translated string. If the call fails, the caught exception message identifies the error cause.

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.alimt.Model.V20181012;

class TestProgram
{
    static void Main(string[] args)
    {
        // Initialize the client with your AccessKey credentials
        IClientProfile profile = DefaultProfile.GetProfile(
            "cn-hangzhou",
            "<your-access-key-id>",
            "<your-access-key-secret>");
        DefaultAcsClient client = new DefaultAcsClient(profile);

        try
        {
            // Build the translation request
            TranslateGeneralRequest request = new TranslateGeneralRequest();
            request.Method = "POST";
            request.FormatType = "text";
            request.SourceLanguage = "en";
            request.SourceText = "Hello";
            request.TargetLanguage = "zh";

            // Send the request and print the translated text
            TranslateGeneralResponse response = client.GetAcsResponse(request);
            System.Console.WriteLine(response.Data);
        }
        catch (ServerException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
        catch (ClientException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    }
}

Replace <your-access-key-id> and <your-access-key-secret> with your actual credentials. In production, read credentials from environment variables or a configuration file rather than hard-coding them.

What's next