Amazon web services Amazon SDK导致无效的IL代码异常-知道什么';是什么原因造成的?

Amazon web services Amazon SDK导致无效的IL代码异常-知道什么';是什么原因造成的?,amazon-web-services,amazon-ec2,Amazon Web Services,Amazon Ec2,我浏览过互联网。任何地方都没有提到AmazonSDK的IL代码异常,但我得到了它们 我得到了一个完全废弃的异常,它表示“无效的IL代码”和散列垃圾。我在框架4.6.1、4.5.2甚至Core上试过这个。它们都一样 目标机器:Ubuntu 16.04/mono 我在尝试建立凭据时遇到与创建ec2Client时相同的错误。 首先,我按照Amazon文档获取如下凭证: CredentialProfileStoreChain chain = new CredentialProfileStoreChain

我浏览过互联网。任何地方都没有提到AmazonSDK的IL代码异常,但我得到了它们

我得到了一个完全废弃的异常,它表示“无效的IL代码”和散列垃圾。我在框架4.6.1、4.5.2甚至Core上试过这个。它们都一样

目标机器:Ubuntu 16.04/mono

我在尝试建立凭据时遇到与创建ec2Client时相同的错误。

首先,我按照Amazon文档获取如下凭证:

CredentialProfileStoreChain chain = new CredentialProfileStoreChain("/home/ubuntu/.aws/credentials");
AWSCredentials awsCredentials;
chain.TryGetAWSCredentials("default", out awsCredentials))
ec2Client = new AmazonEC2Client("{MYKEYID}", "{MYSECRETKEY}");
这给了我一个例外:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.CredentialManagement.SharedCredentialsFile' threw an exception. ---> System.InvalidProgramException: Invalid IL code in System.Collections.Generic.HashSet`1<T_REF>:.ctor (System.Collections.Generic.IEqualityComparer`1<T_REF>): method body is empty.

  at Amazon.Runtime.CredentialManagement.SharedCredentialsFile..cctor () <0x407090c0 + 0x0006a> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Amazon.Runtime.CredentialManagement.CredentialProfileStoreChain.TryGetProfile (System.String profileName, Amazon.Runtime.CredentialManagement.CredentialProfile& profile) <0x40708f30 + 0x000ce>...
    System.TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.Auth.AWS4Signer' threw an exception. ---> System.InvalidProgramException: Invalid IL code in System.Collections.Generic.HashSet`1<T_REF>:.ctor (System.Collections.Generic.IEqualityComparer`1<T_REF>): method body is empty.

  at Amazon.Runtime.Internal.Auth.AWS4Signer..cctor () <0x40d5b830 + 0x000b2> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Amazon.EC2.AmazonEC2Client.CreateSigner () <0x40d5b7b0 + 0x0002f> in <filename unknown>:0
  at Amazon.Runtime.AmazonServiceClient..ctor (Amazon.Runtime.AWSCredentials credentials, Amazon.Runtime.ClientConfig config) <0x40d526d0 + 0x00142> in <filename unknown>:0
  at Amazon.Runtime.AmazonServiceClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.Runtime.ClientConfig config) <0x40d52350 + 0x00067> in <filename unknown>:0
  at Amazon.EC2.AmazonEC2Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.EC2.AmazonEC2Config clientConfig) <0x40d52310 + 0x00023> in <filename unknown>:0
  at Amazon.EC2.AmazonEC2Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey) <0x40d4ec00 + 0x0005d> in <filename unknown>:0
然后我得到一个例外:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Amazon.Runtime.CredentialManagement.SharedCredentialsFile' threw an exception. ---> System.InvalidProgramException: Invalid IL code in System.Collections.Generic.HashSet`1<T_REF>:.ctor (System.Collections.Generic.IEqualityComparer`1<T_REF>): method body is empty.

  at Amazon.Runtime.CredentialManagement.SharedCredentialsFile..cctor () <0x407090c0 + 0x0006a> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Amazon.Runtime.CredentialManagement.CredentialProfileStoreChain.TryGetProfile (System.String profileName, Amazon.Runtime.CredentialManagement.CredentialProfile& profile) <0x40708f30 + 0x000ce>...
    System.TypeInitializationException: The type initializer for 'Amazon.Runtime.Internal.Auth.AWS4Signer' threw an exception. ---> System.InvalidProgramException: Invalid IL code in System.Collections.Generic.HashSet`1<T_REF>:.ctor (System.Collections.Generic.IEqualityComparer`1<T_REF>): method body is empty.

  at Amazon.Runtime.Internal.Auth.AWS4Signer..cctor () <0x40d5b830 + 0x000b2> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at Amazon.EC2.AmazonEC2Client.CreateSigner () <0x40d5b7b0 + 0x0002f> in <filename unknown>:0
  at Amazon.Runtime.AmazonServiceClient..ctor (Amazon.Runtime.AWSCredentials credentials, Amazon.Runtime.ClientConfig config) <0x40d526d0 + 0x00142> in <filename unknown>:0
  at Amazon.Runtime.AmazonServiceClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.Runtime.ClientConfig config) <0x40d52350 + 0x00067> in <filename unknown>:0
  at Amazon.EC2.AmazonEC2Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.EC2.AmazonEC2Config clientConfig) <0x40d52310 + 0x00023> in <filename unknown>:0
  at Amazon.EC2.AmazonEC2Client..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey) <0x40d4ec00 + 0x0005d> in <filename unknown>:0
System.TypeInitializationException:“Amazon.Runtime.Internal.Auth.AWS4Signer”的类型初始值设定项引发异常。-->System.InvalidProgrameException:System.Collections.Generic.HashSet`1:.ctor(System.Collections.Generic.IEqualityComparer`1)中的IL代码无效:方法体为空。
在:0中的Amazon.Runtime.Internal.Auth.AWS4Signer..cctor()处
---内部异常堆栈跟踪的结束---
位于:0中的Amazon.EC2.AmazonEC2Client.CreateSigner()
位于:0中的Amazon.Runtime.AmazonServiceClient..ctor(Amazon.Runtime.AWSCredentials凭据,Amazon.Runtime.ClientConfig配置)
在:0中的Amazon.Runtime.AmazonServiceClient..ctor(System.String awsAccessKeyId,System.String AWSSeCessKey,Amazon.Runtime.ClientConfig config)中
位于:0中的Amazon.EC2.AmazonEC2Client..ctor(System.String awsAccessKeyId,System.String awsSecretAccessKey,Amazon.EC2.AmazonEC2Config clientConfig)
在:0中的Amazon.EC2.AmazonEC2Client..ctor(System.String awsAccessKeyId,System.String awsSecretAccessKey)处
重述:我对Amazon SDK进行了两次完全不同的函数调用,两次调用都给了我一个常见错误:

System.Collections.Generic.HashSet
1:.ctor(System.Collections.Generic.IEqualityComparer
1)中的IL代码无效:方法体为空

有人知道这是什么原因吗

旁注:作为旁注,出于某种奇怪的原因,我得到了缺少System.XML.Linq和缺少System.Core的错误,除非我专门将它们从Microsoft的默认位置复制到我的bin文件夹中。当我进行构建时,它们不会自动放在那里。我是不是完全用错了SDK

编辑:JamesHoux 2018年7月20日下午2:43。您的系统上不存在此文件

这应该是“/home/ubuntu/.aws/credentials”

注意:如果您的用户名与“ubuntu”不同,请更改“/home/ubuntu”部分

按照此操作并验证您的凭据是否正确创建

注意:您也可以让系统通过以下方式(从默认位置)查找凭证文件:

var chain = new CredentialProfileStoreChain();
解决了这个问题。“无效的IL代码”字面意思就是:无法执行的坏代码

在Mono上运行时,IL代码无效通常意味着:

1) 您的Mono版本需要更新

2) 您正在使用/运行的库或程序与Mono(或您的Mono版本)不兼容


我们测试的服务器有一个旧版本的Mono,因为我们错误地依赖Ubuntu存储库来安装Mono,而不是从Mono项目网站获得最新的官方版本。更新Mono修复了该问题。不再出现IL代码错误。

Wow。为什么CredentialProfileStoreChain在问题简单到丢失文件的情况下抛出如此令人讨厌的错误?你会认为文件打开命令会引发一个典型的错误,Amazon的API应该拦截并抛出它自己的异常,给你一些比这个混乱更有意义的东西。我是C++老手。我只是讨厌这些堆积如山的垃圾。我最喜欢的另一种语言,Python也做同样的事情。经过大量测试,我非常确定错误的文件不是问题所在。我按照您的建议将文件移动到/home/ubuntu/.aws/credentials。我还使用System.IO.StreamReader读取文件并转储输出以验证其正确性。这是正确的。我还将App.Config亚马逊参数转储到控制台。这些也是正确的。无论我做什么,错误都是一样的。