All Products
Search
Document Center

Alibaba Cloud SDK:FAQ

Last Updated:Apr 15, 2025

This topic provides answers to some frequently asked questions (FAQ) about the use of Alibaba Cloud SDK for .NET to help you improve the development efficiency.

Prerequisites

.NET Framework 4.5 or later or .NET Core 2.0 or later is installed.

Overview

Question 1: How do I handle AccessKey errors?

Problem: The following error message is returned when I run my code. The error message prompts that the AccessKey pair is incorrect.

  • Alibaba Cloud SDK V2.0: Unhandled exception. Tea.TeaException: Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly.

  • Alibaba Cloud SDK V1.0: Unhandled exception. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'Access key ID cannot be null.')

Solutions:

  1. Run the following commands to check whether the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured:

    Linux or macOS

    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

    Windows

    echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
    echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%

    If a valid AccessKey pair is returned, the environment variables are correctly configured. If no AccessKey pair is returned or the returned AccessKey pair is invalid, reconfigure the environment variables. For more information, see Configure environment variables in Linux, macOS, and Windows.

  2. Check for AccessKey-related errors in the code.

    Sample invalid configurations:

     AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
                {
                    AccessKeyId = Environment.GetEnvironmentVariable("yourAccessKeyID"),
                    AccessKeySecret = Environment.GetEnvironmentVariable("yourAccessKeySecret"),
                };

    Sample valid configurations:

     AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
                {
                    AccessKeyId = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                    AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
                };
    Note

    Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID") and Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET") indicate that the values are obtained from the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

    Important

    To prevent AccessKey leaks, do not write the AccessKey pair in plaintext directly in your code.

Question 2: What do I do if the "TimeoutException..." error message is returned?

An API call timeout may be caused by multiple factors. The following section describes the common causes and the corresponding solutions.

Network connectivity issues

Cause: The API request cannot reach the destination server because the network connection between the client and server fails or the network is unstable.

Solutions:

Use the ping or curl command to test the connectivity between the on-premises host and the endpoint of the cloud service. For example, if a Short Message Service (SMS) API operation call times out, run the ping dysmsapi.aliyuncs.com or curl -v https://dysmsapi.aliyuncs.com command to test the network connectivity.

  • If the command times out or no response is returned, check whether a block policy is configured on the on-premises firewall or router.

  • If a response is returned, we recommend that you specify an appropriate timeout period to prevent request failures caused by improper configurations. For more information, see Configure a timeout period. Sample code:

    // Configure the timeout period for connection requests by using runtime parameters. The timeout period takes effect only for requests that use RuntimeOptions.
    RuntimeOptions runtimeOptions = new RuntimeOptions();
    runtimeOptions.ConnectTimeout = connectionTimeoutMillis;

Long processing time of the API request

Cause: The time for processing the API request exceeds the specified read timeout period.

Solution: Extend the read timeout period for the API response. For more information, see Configure a timeout period. For example, you can configure the read timeout parameter to extend the read timeout period. Sample code:

// Configure the timeout period for read requests by using runtime parameters. The timeout period takes effect only for requests that use RuntimeOptions.
RuntimeOptions runtimeOptions = new RuntimeOptions();
runtimeOptions.ReadTimeout = readTimeoutMillis;

Question 3: What do I do if the "Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'key')" error message is returned?

The Aliyun.Credentials module is outdated. We recommend that you upgrade Aliyun.Credentials to the latest version.

dotnet add package Aliyun.Credentials

Checklist of basic C# exceptions

Error message

Cause

Solution

SocketException

A socket-related error occurred. For example, the connection timed out, or the connection was closed.

Run a cURL command to check the availability of the network connection. Make sure that the destination host and port number are correct.

HttpRequestException

An HTTP request-related error occurred. For example, the server cannot be connected or the request timed out.

Check the network connection and make sure that the server is running. You can use a try-catch block to catch and handle this exception.

ProtocolViolationException

A network protocol-related error occurred. For example, the HTTP request or response was invalid.

Check the network protocol and make sure that the request and response meet the protocol requirements. You can use conditional statements or an exception handling mechanism to handle this exception.

TimeoutException

An operation timed out.

Increase the timeout period or optimize the performance to ensure that the operation can be complete before the specified timeout period ends. You can use conditional statements or an exception handling mechanism to handle this exception.

DNS resolution failure

The domain name cannot be resolved or is invalid.

Check the domain name and make sure that the DNS server is available. You can use conditional statements or an exception handling mechanism to handle this exception.

Technical support

If you encounter other issues when you use Alibaba Cloud SDK, contact us in the following way:

  • Submit a ticket.

  • If you have questions or feedback, contact technical support in the DingTalk group 60965016010.