Skip to content

RegisterSigV4aProvider doesn't work with AOT #3969

@jamiewinder

Description

@jamiewinder

Describe the bug

I have a simple AOT application which sending an event to EventBridge using a global endpoint.

If I run this application, I get an error at runtime:

Unhandled Exception: Amazon.RuntimeDependencies.MissingRuntimeDependencyException: Operation failed because of a missing runtime dependency. In Native AOT builds runtime dependencies can not be dynamically loaded from assembles. Instead the runtime dependency needs to be explicitly registered. To complete this operation register an instance of Amazon.Extensions.CrtIntegration.CrtAWS4aSigner from package AWSSDK.Extensions.CrtIntegration using the operation Amazon.RuntimeDependencies.GlobalRuntimeDependencyRegistry.Instance.RegisterSigV4aProvider.

If I add what I believe to be the required code (see repro below) I get another error:

Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Aws.Crt.NativeAPI.BindImplD + 0x65
at Aws.Crt.Auth.AwsSigner.API..cctor() + 0x19

Could be I'm doing something wrong, but the registration matches what the error tells me to do.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

RegisterSigV4aProvider should allow Event Bridge global endpoints to be used.

Current Behavior

RegisterSigV4aProvider results in another error.

Reproduction Steps

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AWSSDK.EventBridge" Version="4.0.3.5" />
    <PackageReference Include="AWSSDK.Extensions.CrtIntegration" Version="4.0.0" />
  </ItemGroup>

</Project>
using Amazon.EventBridge;
using Amazon.EventBridge.Model;
using Amazon.Extensions.CrtIntegration;
using Amazon.RuntimeDependencies;

GlobalRuntimeDependencyRegistry.Instance.RegisterSigV4aProvider(context =>
{
    return new CrtAWS4aSigner(context.SigV4aCrtSignerContextData.SignPayload);
});

var client = new AmazonEventBridgeClient();

var request = new PutEventsRequest
{
    EndpointId = "my-endpoint-id",
    Entries =
    [
        new PutEventsRequestEntry
        {
            Detail = "TEST",
            DetailType = "MyDetailType",
            Source = "MySource",
            EventBusName = "default"
        }
    ]
};

var response = await client.PutEventsAsync(request);

Console.WriteLine(response.HttpStatusCode);

If this is published and ran, the error will occur.

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.EventBridge 4.0.3.5
AWSSDK.Extensions.CrtIntegration 4.0.0

Targeted .NET Platform

.NET 8

Operating System and version

Windows 10 / Linux

Metadata

Metadata

Assignees

Labels

aotAhead of TimebugThis issue is a bug.credentialsp2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions