I am currently following Amazon's AWSSDK documentation (in particular: this) in an attempt to access AmazonS3 data on a Xamarin forms application. I ran into an error, so I started a fresh project with fresh packages, all up to date as far as I can tell, and am still encountering the same problem.
Here is the current code for the main code behind class:
public partial class MainPage : ContentPage
{
private static IAmazonS3 client;
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
public MainPage()
{
InitializeComponent();
// I have tried each of the following:
client = new AmazonS3Client(); <--- ERROR
client = new AmazonS3Client(RegionEndpoint.USWest2); <-- SIMILAR ERROR
client = new AmazonS3Client(bucketRegion); <-- SAME ERROR
// This has a different error, lack of RegionEndpoint, which is expected, but at least this seems to be recognized
client = new AmazonS3Client(new AnonymousAWSCredentials());
}
}
This results in the following runtime error on the indicated line:
Method not found: void Amazon.S3.AmazonS3Client..ctor()
I understand that MethodNotFoundExceptions often are the result of old versions of DLLs hanging around, outdated dependencies, duplicate assemblies, etc, but I have deployed this from a completely fresh project with the only packages installed being the up-to-date standard Xamarin packages and the Amazon.S3 package.
What is causing this error?
The problem has nothing to do with "old dlls, outdated dependencies" etc. If you look at the example you're following, they're not trying to call the default ctor, they're initializing it via a repository region .
If you take a look at the simple cross-platform application using the AWS SDK for .NET (or even the documentation within the IDE you're using), you can see that when you use the default ctor, you need:
Before running this application, credentials must be specified in the [default] profile or another profile, and then the AWS_PROFILE environment variable must be set. A region must be specified in the [default] profile or by setting the AWS_REGION environment variable.
The docs also say that App.config can be used.
But since we'll be using it for Xamarin, it will be much easier to use some of the other overloads. Here are some of them:
Let's say you want to use AWSCredentials to generate your client. Again, you have many options here:
NB: When you initialize your client, it's good practice to specify the RegionEndpoint . In most cases, if you forget, you'll get an AmazonClientException: No RegionEndpoint or ServiceURL configured , so it reminds you that it's required.
Edit: Due to an update to your question, here's an update from me: The same rules apply for factors you've tested. They are looking for credentials in configuration files, which are not present for a Xamarin.Forms application. To use the client, you need to know your credentials. If you need to use the client, provide some credentials during initialization: use some of the other AWSCredentials: Basic , Federated , etc., or use the simpler one, with accessKeyId + accessKey .
If you're curious why the factors you tried don't work, or what they're doing behind the scenes, their SDK is open sourced here . The empty ctor code is here and the more interesting FallbackCredentialsFactory here .