aliyun / aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET
https://www.nuget.org/profiles/aliyun-openapi-sdk
Other
541 stars 625 forks source link

LoadEndpointDocument()会报NullReferenceException异常 #50

Closed OrchesAdam closed 6 years ago

OrchesAdam commented 6 years ago

运行环境 :

.NET Core 2.1 aliyun.acs.core.netcore 1.1.4.1 通过 nuget 安装

在使用Aliyun.Acs.Dysmsapi 发送短信的时候,会出现异常

异常详细信息

System.Xml.XmlReader.CalcBufferSize(Stream input)
System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, string baseUriStr, Stream stream, byte[] bytes, int byteCount, Encoding encoding)
System.Xml.XmlTextReaderImpl..ctor(string url, Stream input, XmlNameTable nt)
System.Xml.XmlDocument.Load(Stream inStream)
Aliyun.Acs.Core.Regions.InternalEndpointsParser.LoadEndpointDocument()
Aliyun.Acs.Core.Regions.InternalEndpointsParser.GetEndpoints()
Aliyun.Acs.Core.Profile.DefaultProfile.GetEndPointsFromLocal()
Aliyun.Acs.Core.Profile.DefaultProfile.GetEndpoints(string regionId, string product, Credential credential, string locationProduct)
Aliyun.Acs.Core.DefaultAcsClient.DoAction<T>(AcsRequest<T> request, bool autoRetry, int maxRetryNumber, IClientProfile profile)
Aliyun.Acs.Core.DefaultAcsClient.DoAction<T>(AcsRequest<T> request)
Aliyun.Acs.Core.DefaultAcsClient.GetAcsResponse<T>(AcsRequest<T> request)

经过简单的debug后发现 在InternalEndpointsParser这个类中,获取xml文件的方法

Assembly.GetExecutingAssembly().GetManifestResourceStream(name)

取到的值为空,下面是调试窗口输出的信息

Assembly.GetExecutingAssembly().GetManifestResourceStream("Aliyun.Acs.Core.Regions.endpoints.xml")
null

似乎是 xml的路径的问题,使用 下面这个方法

 this.GetType().GetTypeInfo().Assembly.GetManifestResourceNames()
    {string[1]}
        [0]: "Aliyun.Acs.Core.NetCore.Regions.endpoints.xml"

返回的Aliyun.Acs.Core.NetCore.Regions.endpoints.xml能够获取到xml的信息,而程序获取的路径Aliyun.Acs.Core.Regions.endpoints.xml取不到