Forum Xamarin.Forms

MissingMethodException: Method not found: Amazon.S3.Transfer.TransferUtility.DownloadAsync

SwiftestSwiftest USMember ✭✭
edited September 2019 in Xamarin.Forms

I'm getting this exception in a Xamarin.Forms app while testing both Android and UWP projects. (No iOS test yet.)

When I debug in Visual Studio 2017/2019, the instantiated TransferUtility object does not list any of the expected methods.

All Nugets have been updated. The Aws Nugets are in the Forms project, and I also tried adding them to the Android and UWP projects as well.

  • AWSSDK.CognitoIdentity v3.3.100.75
  • AWSSDK.Core v3.3.103.39
  • AWSSDK.S3 v3.3.104.27

Method not found: 'System.Threading.Tasks.Task Amazon.S3.Transfer.TransferUtility.DownloadAsync(System.String, System.String, System.String, System.Threading.CancellationToken)'.

Note that it's not just UploadAsync(), but also Upload() and I don't see any of the Download* methods either. As soon as I step into the the S3Upload method, I get the exception.

The code lives in the Xamarin.Forms project, is very basic, and it works for a stand alone Xamarin Mac application, but not for Xamarin.Forms:

    public async Task S3Upload()
    {
        try // The exception occurs as soon as I try to step into this method
        {
            // Initialize the Amazon Cognito credentials provider
            var credentials = new CognitoAWSCredentials(
                "us-east-1:not-my-real-id", // Identity pool ID
                RegionEndpoint.USEast1 // Region
            );
            IAmazonS3 s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);


            var filePath = [email protected]"path-to-the-file"; // not the real path, but we never get to this line

            var info = new FileInfo(filePath);

            var xfer = new TransferUtility(s3Client);
            //var xfer = new TransferUtilityUploadRequest
            //{
            //    BucketName = bucketName,
            //    Key = info.Name,

            //};

            if (info.Exists)
            {
                //xfer.Upload(filePath, bucketName);
                await xfer.UploadAsync(filePath, bucketName);
            }
            else
            {
                //xfer.Download(filePath, bucketName, info.Name);
                await xfer.DownloadAsync(filePath, bucketName, info.Name);
            }
        }
        catch (AmazonS3Exception amazonS3Exception)
        {
            if (amazonS3Exception.ErrorCode != null &&
                (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                 amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
            {
                Console.WriteLine("Please check the provided AWS Credentials.");
                Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
            }
            else
            {
                Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
            }
        }
    }

Any tips or pointers appreciated!

Answers

  • SwiftestSwiftest USMember ✭✭

    Does anybody else use AWS S3 with Xamarin.Forms? Or should I just migrate to Azure which seems better supported on Xamarin?

  • SharkmanSharkman Member

    I have the same issue. Did you ever resolve this?

  • PhilipOGormanPhilipOGorman USMember ✭✭✭
    edited March 2020

    This works fine for me
    `

                var s3Object = await amazonS3.GetObjectAsync(new GetObjectRequest()
                {
    
                    BucketName = bucket,
    
                    Key = key
    
                });
    
                response.FileName = s3Object.Key;
    
                response.FileStream = s3Object.ResponseStream;
    

    `

  • I had a similar issue too, and I managed to solve it. I've detailed my debugging process in Stackover. Here's the link to the question thread. (I'm sorry, I can't provide the link as I have just created this account. You will have to google search my question thread) How to resolve exception System.MissingMethodException: 'Method not found: void Amazon.S3.Transfer.TransferUtility.Upload()' (Xamarin AWS S3)

    I suspect that the exception occurs because we were using the credentials from Amazon Cognito credentials provider. Perhaps you could try using the credentials from your IAM user, instead of using the credentials provided by Amazon Cognito credentials provider?

Sign In or Register to comment.