【问题标题】:Cake build script calling AWS.ElasticBeanstalk DescribeEnvironments() throwing MissingMethodException蛋糕构建脚本调用 AWS.ElasticBeanstalk DescribeEnvironments() 抛出 MissingMethodException
【发布时间】:2018-11-09 20:48:17
【问题描述】:

这是一个非常具体的错误,过去几天我一直在调查它,但遇到了死胡同。

我的蛋糕构建脚本中的一个任务是尝试检查弹性 beanstalk 环境是否已准备好。我们一直在使用这个插件 (https://github.com/mathieukempe/Cake.AWS.ElasticBeanstalk) 我派生了 repo 以添加 DescribeEnvironments() 实现。如果我直接在控制台应用程序中运行插件代码,它就可以工作。但是,当我从蛋糕构建脚本运行它时,它会抛出 System.MissingMethodException: Method not found: 'System.String Amazon.Runtime.Internal.Util.StringUtils.FromDateTimeToISO8601(System.DateTime)' 不幸的是,我认为我是互联网上唯一遇到此问题的人。

下面是我的蛋糕脚本正在运行的任务:

Task("CheckEBEnvironment")
.Does((context) => {
    var settings = CreateElasticBeanstalkSettings();
    if (context.ApplicationVersionReady(settings, ebApplication, ebEnvironment, ebVersion)) {
        Information("Environment ready.");
        isReady = true;
    } else {
        Information("Environment not ready...");
    } 
});

下面是插件代码:

[CakeAliasCategory("AWS")]
[CakeNamespaceImport("Amazon")]
[CakeNamespaceImport("Amazon.ElasticBeanstalk")]
public static class ElasticBeanstalkAliases
{
    private static IElasticBeanstalkManager CreateManager(this ICakeContext context)
    {
        return new ElasticBeanstalkManager(context.Environment, context.Log);
    }

    // ...

    [CakeMethodAlias]
    [CakeAliasCategory("ElasticBeanstalk")]
    public static bool ApplicationVersionReady(this ICakeContext context, ElasticBeanstalkSettings settings, string applicationName, string environmentName, string versionLabel)
    {
        var manager = context.CreateManager();
        return manager.ApplicationVersionReady(settings, applicationName, environmentName, versionLabel);
    }
}

这里是实现:

public class ElasticBeanstalkManager : IElasticBeanstalkManager
{
    private readonly ICakeEnvironment _Environment;
    private readonly ICakeLog _Log;

    /// <summary>
    /// If the manager should output progrtess events to the cake log
    /// </summary>
    public bool LogProgress { get; set; }

    public ElasticBeanstalkManager(ICakeEnvironment environment, ICakeLog log)
    {
        if (environment == null)
        {
            throw new ArgumentNullException("environment");
        }
        if (log == null)
        {
            throw new ArgumentNullException("log");
        }

        _Environment = environment;
        _Log = log;

        this.LogProgress = true;
    }

    //Request
    private AmazonElasticBeanstalkClient GetClient(ElasticBeanstalkSettings settings)
    {
        if (settings == null)
        {
            throw new ArgumentNullException("settings");
        }

        if (settings.Region == null)
        {
            throw new ArgumentNullException("settings.Region");
        }

        if (settings.Credentials == null)
        {
            if (String.IsNullOrEmpty(settings.AccessKey))
            {
                throw new ArgumentNullException("settings.AccessKey");
            }
            if (String.IsNullOrEmpty(settings.SecretKey))
            {
                throw new ArgumentNullException("settings.SecretKey");
            }

            return new AmazonElasticBeanstalkClient(settings.AccessKey, settings.SecretKey, settings.Region);
        }
        else
        {
            return new AmazonElasticBeanstalkClient(settings.Credentials, settings.Region);
        }
    }

    public bool ApplicationVersionReady(ElasticBeanstalkSettings settings, string applicationName, string environmentName, string versionLabel)
    {
        if (string.IsNullOrEmpty(applicationName))
        {
            throw new ArgumentNullException(nameof(applicationName));
        }

        if (string.IsNullOrEmpty(environmentName))
        {
            throw new ArgumentNullException(nameof(environmentName));
        }

        if (string.IsNullOrEmpty(versionLabel))
        {
            throw new ArgumentNullException(nameof(versionLabel));
        }

        var client = GetClient(settings);
        var status = client.DescribeEnvironmentsAsync(new DescribeEnvironmentsRequest
        {
            ApplicationName = applicationName,
            EnvironmentNames = new List<string>(new[] {environmentName}),
            VersionLabel = versionLabel,
            IncludeDeleted = false,
        }).Result.Environments[0].Status.Value;

        return status == "Ready";
    }
}

这是整个异常消息:

System.AggregateException:发生一个或多个错误。 ---> System.MissingMethodException:找不到方法:'System.String Amazon.Runtime.Internal.Util.StringUtils.FromDateTimeToISO8601(System.DateTime)'。 在 Amazon.ElasticBeanstalk.Model.Internal.MarshallTransformations.DescribeEnvironmentsRequestMarshaller.Marshall(DescribeEnvironmentsRequest publicRequest) 在 Amazon.Runtime.Internal.Marshaller.PreInvoke(IExecutionContext executionContext) 在 Amazon.Runtime.Internal.Marshaller.InvokeAsync[T](IExecutionContext executionContext) 在 Amazon.Runtime.Internal.CallbackHandler.d__91.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__51.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 Amazon.Runtime.Internal.MetricsHandler.d__11.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task1.GetResultCore(布尔 waitCompletionNotification) 在 Cake.AWS.ElasticBeanstalk.ElasticBeanstalkManager.ApplicationVersionReady(ElasticBeanstalkSettings 设置,字符串应用程序名称,字符串环境名称,字符串版本标签) 在提交#0.b__0_11(ICakeContext 上下文) --->(内部异常#0)System.MissingMethodException:找不到方法:'System.String Amazon.Runtime.Internal.Util.StringUtils.FromDateTimeToISO8601(System.DateTime)'。 在 Amazon.ElasticBeanstalk.Model.Internal.MarshallTransformations.DescribeEnvironmentsRequestMarshaller.Marshall(DescribeEnvironmentsRequest publicRequest) 在 Amazon.Runtime.Internal.Marshaller.PreInvoke(IExecutionContext executionContext) 在 Amazon.Runtime.Internal.Marshaller.InvokeAsync[T](IExecutionContext executionContext) 在 Amazon.Runtime.Internal.CallbackHandler.d__91.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__51.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 Amazon.Runtime.Internal.MetricsHandler.d__1`1.MoveNext()

我的猜测是,蛋糕上下文在某处为请求设置了日期时间,这是亚马逊无法处理的格式。如果有人有任何想法或遇到类似问题,我将不胜感激。

【问题讨论】:

    标签: c# .net amazon-elastic-beanstalk iso8601 cakebuild


    【解决方案1】:

    我的猜测是,您缺少一些依赖项。

    由于错误状态,无法找到方法Amazon.Runtime.Internal.Util.StringUtils.FromDateTimeToISO8601(System.DateTime)。查看 nuget.org 上的 Cake addin you mentioned,它表明它对 AWSSDK.CoreAWSSDK.ElasticBeanstalk 包有一些依赖关系。在第一个的 github 项目上你可以看到,这就是 the method is implemented

    所以我猜你在构建分叉插件时没有指定这些依赖项,因此会发生错误。如果您构建一个 nuget 包,请将这些包添加为依赖项(与原始插件相同的方式)。

    【讨论】:

    • 这是我的想法,但我仔细检查并确保 AWSSDK.Core.dll 包含在 nuget 包中,并且在 cake 安装所有插件后出现在插件文件夹中。我什至反编译了 .dll 以确保该方法确实存在并且确实存在。
    【解决方案2】:

    我发现了这个问题。我使用了两个插件,第一个是Cake.AWS.S3,第二个是Cake.AWS.ElasticBeanstalk,因为当蛋糕需要引用AWSSDK.Core.dll时首先定义了S3插件,所以它将使用S3插件提供的.dll,恰好是比 ElasticBeanstalk 插件预期的旧版本,导致它调用不存在的方法。

    如果我首先简单地定义 Cake.AWS.ElasticBeanstalk 插件,它就可以工作。我可能会提交拉取请求以升级 S3 插件的 AWSSDK.Core.dll

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多