c# - AWS .NET SDK SimpleEmail SendEmail 返回 'Could not load type' 错误

标签 c# .net amazon-web-services aws-sdk

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

Could not load type 'Amazon.Runtime.Internal.InvokeOptions' from assembly '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> {
            "user@cuchuma.net",
            "user2@cuchuma.net"
        }
    },
    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 = "no-reply@cuchuma.net",
    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 = ""

关于c# - AWS .NET SDK SimpleEmail SendEmail 返回 'Could not load type' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54599210/

相关文章:

amazon-web-services - AWS EBS 卷未挂载,但没有错误消息

c# - 加载目录中的所有部分

c# - 使用反射设置嵌套属性值

c# - SQL CLR 函数返回可为空的 bool 值

postgresql - 从 RDS postgres 只读副本和 sqlalchemy 流式传输大型结果集过早终止

amazon-web-services - Terraform 多状态文件最佳实践示例

c# - 使用 mySQL 将 int 列表传递给 dapper

c# - 此命名空间冲突是由于 XAML 到 .NET 代码生成中的错误造成的吗?

c# - 如何使用 FluentMigrator 删除列?

c# - 从 .NET 使用 SAP Web 服务会抛出异常 ServiceModel.FaultException