I am hitting an unhandled TaskCanceledException every time my code invokes an AWS Lambda. The code runs on an Android device. (It's written in C# with Xamarin.Android and references AWSSDK
.Core, AWSSDK.Lambda).
- Why is the task timing out? [Update: this has been figured out]
 
- Why isn't the exception handled?
 
- Why can't I see any diagnostics from AWS SDK for .NET in the logs?
 
Code:
public class SomeActivity: Activity
{
    private AmazaonLambdaClient mAWSLambdaClient;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(...);
        FindViewById(...).Click += ButtonClickAsync;
        // System.Diagnostics.Trace redirects to Log.Debug with TAG="System.Diagnostics.Trace"
        System.Diagnostics.Trace.Listeners.Add(new MyAndroidTraceListener("System.Diagnostics.Trace"));
        System.Diagnostics.Trace.TraceInformation("Android trace listener installed");
        // AWS logs to System.Diagnostics
        AWSConfigs.LoggingConfig.LogTo = LoggingOptions.SystemDiagnostics;
        AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
    }
    protected override void OnStart()
    {
        base.OnStart();
        var idToken = ...
        var awsCredentials = new CognitoAWSCredentials("IdentityPoolID", AWSConfig.RegionEndpoint);
        awsCredentials.AddLogin("accounts.google.com", idToken);
        mAWSLambdaClient = new AmazonLambdaClient(awsCredentials, AWSConfig.RegionEndpoint);
    }
    protected override void OnStop()
    {
        base.OnStop();
        mAWSLambdaClient.Dispose();
        mAWSLambdaClient = null;
    }
    private async void ButtonClickAsync(object sender, System.EventArgs e)
    {
         await DoSomethingAsync();
    }
    private async Task DoSomethingAsync()
    {
        var lambdaRequest = ...
        try
        {
            var lambdaInvokeTask = mAWSLambdaClient.InvokeAsync(lambdaRequest);
            invokeResponse = await lambdaInvokeTask; <= VS breaks here after ~30 to 60 seconds
        }
        catch (TaskCanceledException e) // also tried catching Exception, no luck
        {
            Log.Error(TAG, "Lambda Task Canceled: {0}, {1}", e.Message, e.InnerException);
            return;
        }
    }
}
Visual Studio breaks on the await line, telling me I have an unhandled TaskCanceledException: a task was canceled. Weird I do handle that exception. After the unhandled exception, I check the Device Log in Visual Studio. I filter by TAG="System.Diagnostics.Trace" and all I find is:
base apk Information 0:
Android trace listener installed
Where is the AWS SDK log I should have gotten according to logging-with-the-aws-sdk-for-net?
UPDATE:
I've figured out question 1, why it times out. It was due to a lambdaRequest with a bad PayloadStream set to a MemoryStream whose position had not been reset to 0 after JSON serializing an object to the stream.
I have not figured out why 2, the exception wasn't handled by the try/catch, and 3, why AWS SDK did not log as requested.