AWS CognitoSync .NET SDK错误 - 需要将有效的应用程序名称配置为使用此API

时间:2018-01-24 05:42:50

标签: amazon-web-services aws-sdk aws-sdk-net

这是我的CognitoSyncService。当它尝试初始化CognitoSyncManager时会收到错误

  

ArgumentException:需要配置有效的应用程序名称才能使用   此API。可以通过app.config或配置应用程序名称   通过设置Amazon.AWSConfigs.ApplicationName属性。

public class CognitoSyncService
{
   readonly CognitoAWSCredentials _credentials;
   readonly CognitoSyncManager _syncManager;

   public CognitoSyncService(string IdentityPoolId, RegionEndpoint region)
   {
    if (string.IsNullOrEmpty(IdentityPoolId))
        throw new ArgumentNullException("IdentityPoolId can not be null or empty.");

    _credentials = new CognitoAWSCredentials(IdentityPoolId, region);
    _syncManager = new CognitoSyncManager(_credentials, new AmazonCognitoSyncConfig { RegionEndpoint = region });
   }    

   public void CreateDataset(string datasetName)
   {
      _syncManager.OpenOrCreateDataset(datasetName);
   }
}

1 个答案:

答案 0 :(得分:0)

这就是我解决问题的方法。

public CognitoSyncService(string IdentityPoolId, RegionEndpoint region)
{
    if (string.IsNullOrEmpty(IdentityPoolId))
        throw new ArgumentNullException("IdentityPoolId can not be null or empty.");

    if (string.IsNullOrEmpty(AWSConfigs.ApplicationName))
        AWSConfigs.ApplicationName = "my-application-name";

    _credentials = new CognitoAWSCredentials(IdentityPoolId, region);
    _syncManager = new CognitoSyncManager(_credentials, new AmazonCognitoSyncConfig { RegionEndpoint = region });
}