我正在使用AWS SimpleEmail开发应用程序。尝试测试SendEmail功能时出现以下错误。


  无法从中加载类型'Amazon.Runtime.Internal.InvokeOptions'
  程序集'AWSSDK.Core,Version = 3.3.0.0,Culture = neutral,
  PublicKeyToken = 885c28607f98e604'。


我安装了AWSSDK.Core v3.3.31.7和AWSSDK.SimpleEmail v3.3.7.30。

var credentials = new BasicAWSCredentials("key", "secret");

var client = new Amazon.SimpleEmail.AmazonSimpleEmailServiceClient(credentials, Amazon.RegionEndpoint.EUWest1);

var sesResponse = client.SendEmail(new SendEmailRequest
{
    Destination = new Destination
    {
        BccAddresses = new List<string>
        {

        },
        ToAddresses = new List<string> {
            "[email protected]",
            "[email protected]"
        }
    },
    Message = new Message
    {
        Body = new Body
        {
            Html = new Content
            {
                Charset = "UTF-8",
                Data = "This message body contains HTML formatting. It can, for example, contain links like this one: <a class=\"ulink\" href = \"http://docs.aws.amazon.com/ses/latest/DeveloperGuide\" target = \"_blank\"> Amazon SES Developer Guide </a>."
            },
            Text = new Content
            {
                Charset = "UTF-8",
                Data = "This is the message body in text format."
            }
        },
        Subject = new Content
        {
            Charset = "UTF-8",
            Data = "Test email"
        }
    },
    ReplyToAddresses = new List<string>
    {

    },
    ReturnPath = "",
    ReturnPathArn = "",
    Source = "[email protected]",
    SourceArn = ""
});

string messageId = sesResponse.MessageId;

最佳答案

无法加载的类仅添加了2 months ago。因此,我怀疑您拥有的AWSSDK.Core版本比您声明的版本(v3.3.31.7)要旧。

现在,我不确定这种情况如何发生,但是过去我曾看到实例,其中Nuget陷入混乱,而在项目文件中的手动输入会导致加载错误的dll。

在记事本中打开您的项目文件,然后查找SDK参考。它们应如下所示:

<Reference Include="AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
      <HintPath>..\packages\AWSSDK.Core.3.3.31.7\lib\net45\AWSSDK.Core.dll</HintPath>
</Reference>
<Reference Include="AWSSDK.SimpleEmail, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
      <HintPath>..\packages\AWSSDK.SimpleEmail.3.3.7.30\lib\net45\AWSSDK.SimpleEmail.dll</HintPath>
</Reference>


检查软件包名称确实是AWSSDK.Core.3.3.31.7和AWSSDK.SimpleEmail.3.3.7.30。

还要检查是否没有其他随机的AWSSDK.Core条目。

最后...您可能会遇到的另一个问题,如果不指定它们,则不要包括以下带有空字符串的行。它将引发无效的电子邮件地址错误:

ReturnPath = "",
ReturnPathArn = "",
SourceArn = ""

10-05 20:04