Cake构建脚本调用AWS.ElasticBeanstalk DescribeEnvironments()引发MissingMethodException

时间:2018-11-09 20:48:17

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

这是一个非常具体的错误,我已经花了几天的时间进行调查,但是已经走到了尽头。

我的蛋糕构建脚本中的一个任务正在尝试检查弹性beantalk环境是否已准备就绪。我们一直在使用此插件(https://github.com/mathieukempe/Cake.AWS.ElasticBeanstalk)我分叉仓库以添加DescribeEnvironments()实现。如果我直接在控制台应用程序中运行,则插件代码会起作用。但是,当我从cake build脚本运行它时,它会抛出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执行上下文)      在Amazon.Runtime.Internal.Marshaller.InvokeAsync [T](IExecutionContext executeContext)      在Amazon.Runtime.Internal.CallbackHandler.d__9 1.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__5 1.MoveNext()   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在Amazon.Runtime.Internal.MetricsHandler.d__1 1.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task 1.GetResultCore(Boolean waitCompletionNotification)      在Cake.AWS.ElasticBeanstalk.ElasticBeanstalkManager.ApplicationVersionReady(ElasticBeanstalkSettings设置,字符串applicationName,字符串环境名称,字符串versionLabel)      在Submission#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执行上下文)      在Amazon.Runtime.Internal.Marshaller.InvokeAsync [T](IExecutionContext executeContext)      在Amazon.Runtime.Internal.CallbackHandler.d__9 1.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__5 1.MoveNext()   ---从之前引发异常的位置开始的堆栈结束跟踪---      在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()      在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)      在Amazon.Runtime.Internal.MetricsHandler.d__1`1.MoveNext()<---

我的猜测是,蛋糕上下文是在请求上设置日期时间的地方,而日期时间是Amazon无法处理的。如果有人有任何想法或遇到类似问题,我将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

由于错误状态,找不到方法Amazon.Runtime.Internal.Util.StringUtils.FromDateTimeToISO8601(System.DateTime)。在nuget.org上查看Cake addin you mentioned时,它表明它与AWSSDK.CoreAWSSDK.ElasticBeanstalk软件包有一定的依赖性。在第一个github项目上,您可以看到the method is implemented

因此,我猜您在构建派生的插件时没有指定这些依赖项,因此会发生错误。如果您构建nuget程序包,则将这些程序包添加为依赖项(与原始插件相同)。

答案 1 :(得分:0)

我发现了问题。我使用的是两个插件,第一个是 data() { return { idx: undefined }, methods: { closeSibling: function(idx) { console.log("I am emitting" + idx) this.$emit('closeMySibling', this.idx = idx) }, closeMyChild: function() { console.log('closing my child' + this.idx) } ,第二个是Cake.AWS.S3,由于S3插件是在蛋糕需要引用AWSSDK.Core.dll时首先定义的,因此它将使用S3插件提供的.dll。碰巧是比ElasticBeanstalk插件预期的版本更旧的版本,导致它调用了不存在的方法。

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

相关问题