

Version 4 (V4) of the AWS SDK for .NET has been released\$1

For information about breaking changes and migrating your applications, see the [migration topic](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html).

 [https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html)

# Special considerations for the AWS SDK for .NET
<a name="special-considerations"></a>

This section contains considerations for special cases where the normal configurations or procedures aren't appropriate or sufficient.

**Topics**
+ [Obtaining AWSSDK assemblies](net-dg-obtain-assemblies.md)
+ [Accessing credentials and profiles in an application](creds-locate.md)
+ [Unity support](unity-special.md)
+ [Xamarin support](xamarin-special.md)

# Obtaining assemblies for the AWS SDK for .NET
<a name="net-dg-obtain-assemblies"></a>

This topic describes how you can obtain the AWSSDK assemblies and store them locally (or on premises) for use in your projects. This is **not** the recommended method for handling SDK references, but is required in some environments.

**Note**  
The recommended method for handling SDK references is to download and install just the NuGet packages that each project needs. That method is described in [Install AWSSDK packages with NuGet](net-dg-install-assemblies.md).

If you can't or aren't allowed to download and install NuGet packages on a per-project basis, the following options are available to you.

## Download and extract ZIP files
<a name="download-zip-files"></a>

(Remember that this isn't the [recommended method](net-dg-install-assemblies.md) for handling references to the AWS SDK for .NET.)

1. Download one of the following ZIP files:
   + [aws-sdk-net8.0.zip](https://sdk-for-net.amazonwebservices.com/latest/v4/aws-sdk-net8.0.zip) - Assemblies that support .NET 8 and later.
   + [aws-sdk-netcoreapp3.1.zip](https://sdk-for-net.amazonwebservices.com/latest/v4/aws-sdk-netcoreapp3.1.zip) - Assemblies that support .NET Core 3.1 and later.
   + [aws-sdk-netstandard2.0.zip](https://sdk-for-net.amazonwebservices.com/latest/v4/aws-sdk-netstandard2.0.zip) - Assemblies that support .NET Standard 2.0 and 2.1.
   + [aws-sdk-net472.zip](https://sdk-for-net.amazonwebservices.com/latest/v4/aws-sdk-net472.zip) - Assemblies that support .NET Framework 4.5 and later.

1. Extract the assemblies to some "download" folder on your file system; it doesn't matter where. Make note of this folder.

1. When you set up your project, you get the required assemblies from this folder, as described in [Install AWSSDK assemblies without NuGet](net-dg-install-without-nuget.md).

# Accessing credentials and profiles in an application
<a name="creds-locate"></a>

The preferred method for using credentials is to allow the AWS SDK for .NET to find and retrieve them for you, as described in [Credential and profile resolution](creds-assign.md).

However, you can also configure your application to actively retrieve profiles and credentials, and then explicitly use those credentials when creating an AWS service client.

To actively retrieve profiles and credentials, use classes from the [Amazon.Runtime.CredentialManagement](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/NRuntimeCredentialManagement.html) namespace.
+ To find a profile in a file that uses the AWS credentials file format (either the [shared AWS credentials file in its default location](creds-file.md) or a custom credentials file), use the [SharedCredentialsFile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TSharedCredentialsFile.html) class. Files in this format are sometimes simply called *credentials files* in this text for brevity.
+ To find a profile in the SDK Store, use the [NetSDKCredentialsFile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TNetSDKCredentialsFile.html) class.
+ To search in both a credentials file and the SDK Store, depending on the configuration of a class property, use the [CredentialProfileStoreChain](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TCredentialProfileStoreChain.html) class.

  You can use this class to find profiles. You can also use this class to request AWS credentials directly instead of using the `AWSCredentialsFactory` class (described next).
+ To retrieve or create various types of credentials from a profile, use the [AWSCredentialsFactory](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TAWSCredentialsFactory.html) class.

The following sections provide examples for these classes.

## Examples for class CredentialProfileStoreChain
<a name="creds-locate-chain"></a>

You can get credentials or profiles from the [CredentialProfileStoreChain](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TCredentialProfileStoreChain.html) class by using the [TryGetAWSCredentials](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/MCredentialProfileStoreChainTryGetAWSCredentialsStringAWSCredentials.html) or [TryGetProfile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/MCredentialProfileStoreChainTryGetProfileStringCredentialProfile.html) methods. The `ProfilesLocation` property of the class determines the behavior of the methods, as follows:
+ If `ProfilesLocation` is null or empty, search the SDK Store if the platform supports it, and then search the shared AWS credentials file in the default location.
+ If the `ProfilesLocation` property contains a value, search the credentials file specified in the property.

### Get credentials from the SDK Store or the shared AWS credentials file
<a name="creds-locate-chain-get-credentials-default-location"></a>

This example shows you how to get credentials by using the `CredentialProfileStoreChain` class and then use the credentials to create an [AmazonS3Client](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/S3/TS3Client.html) object. The credentials can come from the SDK Store or from the shared AWS credentials file at the default location.

This example also uses the [Amazon.Runtime.AWSCredentials](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TAWSCredentials.html) class.

```
var chain = new CredentialProfileStoreChain();
AWSCredentials awsCredentials;
if (chain.TryGetAWSCredentials("some_profile", out awsCredentials))
{
    // Use awsCredentials to create an Amazon S3 service client
    using (var client = new AmazonS3Client(awsCredentials))
    {
        var response = await client.ListBucketsAsync();
        Console.WriteLine($"Number of buckets: {response.Buckets.Count}");
    }
}
```

### Get a profile from the SDK Store or the shared AWS credentials file
<a name="creds-locate-chain-get-profile-default-location"></a>

This example shows you how to get a profile by using the CredentialProfileStoreChain class. The credentials can come from the SDK Store or from the shared AWS credentials file at the default location.

This example also uses the [CredentialProfile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TCredentialProfile.html) class.

```
var chain = new CredentialProfileStoreChain();
CredentialProfile basicProfile;
if (chain.TryGetProfile("basic_profile", out basicProfile))
{
    // Use basicProfile
}
```

### Get credentials from a custom credentials file
<a name="creds-locate-chain-get-credentials-alternate-location"></a>

This example shows you how to get credentials by using the CredentialProfileStoreChain class. The credentials come from a file that uses the AWS credentials file format but is at an alternate location.

This example also uses the [Amazon.Runtime.AWSCredentials](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TAWSCredentials.html) class.

```
var chain = new
    CredentialProfileStoreChain("c:\\Users\\sdkuser\\customCredentialsFile.ini");
AWSCredentials awsCredentials;
if (chain.TryGetAWSCredentials("basic_profile", out awsCredentials))
{
    // Use awsCredentials to create an AWS service client
}
```

## Examples for classes SharedCredentialsFile and AWSCredentialsFactory
<a name="creds-locate-cred-shared-file"></a>

### Create an AmazonS3Client by using the SharedCredentialsFile class
<a name="creds-locate-cred-shared-file-create-s3-client"></a>

This examples shows you how to find a profile in the shared AWS credentials file, create AWS credentials from the profile, and then use the credentials to create an [AmazonS3Client](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/S3/TS3Client.html) object. The example uses the [SharedCredentialsFile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TSharedCredentialsFile.html) class.

This example also uses the [CredentialProfile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TCredentialProfile.html) class and the [Amazon.Runtime.AWSCredentials](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TAWSCredentials.html) class.

```
CredentialProfile basicProfile;
AWSCredentials awsCredentials;
var sharedFile = new SharedCredentialsFile();
if (sharedFile.TryGetProfile("basic_profile", out basicProfile) &&
    AWSCredentialsFactory.TryGetAWSCredentials(basicProfile, sharedFile, out awsCredentials))
{
    // use awsCredentials to create an Amazon S3 service client
    using (var client = new AmazonS3Client(awsCredentials, basicProfile.Region))
    {
        var response = await client.ListBucketsAsync();
        Console.WriteLine($"Number of buckets: {response.Buckets.Count}");
    }
}
```

**Note**  
The [NetSDKCredentialsFile](https://docs.aws.amazon.com/sdkfornet/v4/apidocs/items/Runtime/TNetSDKCredentialsFile.html) class can be used in exactly the same way, except you would instantiate a new NetSDKCredentialsFile object instead of a SharedCredentialsFile object.

# Special considerations for Unity support
<a name="unity-special"></a>

When using the AWS SDK for .NET and [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) for your Unity application, your application must reference the AWS SDK for .NET assemblies (DLL files) directly rather than using NuGet. Given this requirement, the following are important actions you will need to perform.


+ You need to obtain the AWS SDK for .NET assemblies and apply them to your project. For information about how to do this, see [Download and extract ZIP files](net-dg-obtain-assemblies.md#download-zip-files) in the topic [Obtaining AWSSDK assemblies](net-dg-obtain-assemblies.md).
+ You need to include the following DLLs in your Unity project alongside the DLLs for **AWSSDK.Core** and the other AWS services you're using. Starting with version 3.5.109 of the AWS SDK for .NET, the .NET Standard ZIP file contains these additional DLLs.
  + [Microsoft.Bcl.AsyncInterfaces.dll](https://www.nuget.org/packages/Microsoft.Bcl.AsyncInterfaces/)
  + [System.Runtime.CompilerServices.Unsafe.dll](https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/)
  + [System.Threading.Tasks.Extensions.dll](https://www.nuget.org/packages/System.Threading.Tasks.Extensions/)
+ If you're using [IL2CPP](https://docs.unity3d.com/Manual/IL2CPP.html) to build your Unity project, you must add a `link.xml` file to your Asset folder to prevent code stripping. The `link.xml` file must list all of the AWSSDK assemblies you are using, and each must include the `preserve="all"` attribute. The following snippet shows an example of this file.

  ```
  <linker>
      <assembly fullname="AWSSDK.Core" preserve="all"/>
      <assembly fullname="AWSSDK.DynamoDBv2" preserve="all"/>
      <assembly fullname="AWSSDK.Lambda" preserve="all"/>
  </linker>
  ```

**Note**  
To read interesting background information related to this requirement, see the article at [https://aws.amazon.com/blogs/developer/referencing-the-aws-sdk-for-net-standard-2-0-from-unity-xamarin-or-uwp/](https://aws.amazon.com/blogs/developer/referencing-the-aws-sdk-for-net-standard-2-0-from-unity-xamarin-or-uwp/).

# Special considerations for Xamarin support
<a name="xamarin-special"></a>

Xamarin projects (new and existing) must target .NET Standard 2.0. See [.NET Standard 2.0 Support in Xamarin.Forms](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/internals/net-standard) and [.NET implementation support](https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support).

Also see the information about [Portable Class Library and Xamarin](net-dg-supported-platforms.md#portable-class-library).