我梳理了互联网。没有任何地方提到Amazon SDK的IL代码异常,但是我得到了它们。
我得到了完全解决的异常,该异常说明“无效的IL代码”和哈希垃圾。我在Framework 4.6.1、4.5.2甚至Core上进行了尝试。所有这些都一样。
目标计算机:Ubuntu 16.04 / mono。
我在尝试建立证书时遇到与创建ec2Client时相同的错误。
首先,我按照亚马逊文档获取了这样的凭证:
CredentialProfileStoreChain chain = new CredentialProfileStoreChain("/home/ubuntu/.aws/credentials");
AWSCredentials awsCredentials;
chain.TryGetAWSCredentials("default", out awsCredentials))
哪个给我这个例外:
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>...
其次,由于问题是在TryGetProfile中发生的(从TryGetAWSCredentials()调用),因此我完全删除了先前的凭据查找创建代码。然后,将MyKeyID和MySecretKey方向硬编码为新的AmazonEC2Client函数调用,如下所示:
ec2Client = new AmazonEC2Client("{MYKEYID}", "{MYSECRETKEY}");
然后我得到这个异常:
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
回顾:我对Amazon SDK进行了两个完全不同的函数调用,并且都给了我这个常见错误:
System.Collections.Generic.HashSet 1<T_REF>:.ctor (System.Collections.Generic.IEqualityComparer
1)中无效的IL代码:方法主体为空。
有人知道是什么原因造成的吗?
侧面注意:作为侧面说明,出于某些奇怪的原因,除非我将它们从Microsoft的默认位置专门复制到我的bin文件夹中,否则我会丢失System.XML.Linq和System.Core错误。我进行构建时不会自动将它们放到那里。我只是完全以某种方式完全错误使用了SDK吗?
作者:JamesHoux于2018年7月20日下午2:43
答案 0 :(得分:0)
您的问题是“ / home / ubuntu / aws_credentials”。该文件在您的系统上不存在。
这应该是“ /home/ubuntu/.aws/credentials”
如果您的用户名与“ ubuntu”不同,请注意更改“ / home / ubuntu”部分。
遵循此link并确认您的凭据已正确创建。
请注意,您还可以通过以下方式让系统(从默认位置)找到凭证文件:
var chain = new CredentialProfileStoreChain();
答案 1 :(得分:0)
解决了问题。 “无效的IL代码”的字面意思是:无法执行的错误代码
在Mono上运行时,无效的IL代码通常表示以下一种情况:
1)您的Mono版本需要更新
2)您正在使用/运行的库或程序不适用于Mono(或您的Mono版本)。
我们正在测试的服务器具有旧版本的Mono,因为我们错误地依赖Ubuntu仓库来安装Mono,而不是从Mono项目网站获取最新的正式版本。更新Mono可以解决此问题。没有更多的IL代码错误。