JeffreySu / WeiXinMPSDK

微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
https://weixin.senparc.com
Apache License 2.0
8.43k stars 4.35k forks source link

14.7.1 ShakeAroundApi.GroupAdd();这个方法运行会报错 #864

Closed xuSs1994 closed 7 years ago

xuSs1994 commented 7 years ago

( 此版块专为反馈bug及提交需求服务,不负责解答开发问题,请勿发表开发问题, 如果您需要这方面的帮助,请移步问答社区https://weixin.senparc.com/QA )

问题描述

ShakeAroundApi.GroupAdd();这个方法运行会报错

微信官方文档 URL
微信官方文档快照(直接复制关键内容到下方)

Unhandled Exception: System.InvalidOperationException: The character set provided in ContentType is invalid. Cannot read content as string using an invalid character set. ---> System.ArgumentException: 'utf8' is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. Parameter name: name at System.Globalization.EncodingTable.internalGetCodePageFromName(String name) at System.Globalization.EncodingTable.GetCodePageFromName(String name) at System.Text.Encoding.GetEncoding(String name) at System.Net.Http.HttpContent.ReadBufferAsString(ArraySegment1 buffer, HttpContentHeaders headers) --- End of inner exception stack trace --- at System.Net.Http.HttpContent.ReadBufferAsString(ArraySegment1 buffer, HttpContentHeaders headers) at System.Net.Http.HttpContent.ReadBufferedContentAsString() at System.Net.Http.HttpContent.<>c.b36_0(HttpContent s) at System.Net.Http.HttpContent.d622.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 Senparc.Weixin.HttpUtility.RequestUtility.HttpPost(String url, CookieContainer cookieContainer, Stream postStream, Dictionary2 fileDictionary, String refererUrl, Encoding encoding, X509Certificate2 cer, Int32 timeOut, Boolean checkValidationResult) at Senparc.Weixin.HttpUtility.Post.PostGetJson[T](String url, CookieContainer cookieContainer, Stream fileStream, Encoding encoding, X509Certificate2 cer, Int32 timeOut, Boolean checkValidationResult) at Senparc.Weixin.CommonAPIs.CommonJsonSend.Send[T](String accessToken, String urlFormat, Object data, CommonJsonSendType sendType, Int32 timeOut, Boolean checkValidationResult, JsonSetting jsonSetting) at Senparc.Weixin.MP.AdvancedAPIs.ShakeAroundApi.<>cDisplayClass26_0.b0(String accessToken) at Senparc.Weixin.CommonAPIs.ApiHandlerWapper.ApiHandlerWapperBase.TryCommonApiBase[T](PlatformType platformType, Func1 accessTokenContainer_GetFirstOrDefaultAppIdFunc, Func2 accessTokenContainer_CheckRegisteredFunc, Func3 accessTokenContainer_GetAccessTokenResultFunc, Int32 invalidCredentialValue, Func2 fun, String accessTokenOrAppId, Boolean retryIfFaild) at Senparc.Weixin.MP.ApiHandlerWapper.TryCommonApi[T](Func`2 fun, String accessTokenOrAppId, Boolean retryIfFaild) at IBeaconManage.Program.Main(String[] args) in D:\Project\IBeaconManage\IBeaconManage\Program.cs:line 24

发现问题的模块
模块对应的.net版本
开发环境
缓存环境
lishewen commented 7 years ago

就这一个方法报错吗?

xuSs1994 commented 7 years ago

整个流程这是第一步,调用时报错,下面的也没法继续

xuSs1994 commented 7 years ago

经过测试这个问题只会在.net core下才会出现

lishewen commented 7 years ago

根据发上来的错误堆栈,我去看了下 HttpContent 源码 https://github.com/dotnet/corefx/blob/dev/release/2.0.0/src/System.Net.Http/src/System/Net/Http/HttpContent.cs#L205 如果微信那边返回的 CharSet 真的是 utf8 的话,的确会报你说的错误,因为 Encoding.GetEncoding 承认的参数是 UTF-8 而不是 uft8,这个在以前的 issus 中已经提交过修复的,但现在这段出错代码是 netcore runtime 里面的,参数也是微信那边返回过来的,这个就不好处理了。。。 我晚点提交个临时解决办法再测试下吧

JeffreySu commented 7 years ago

已经发布到Nuget的一个隐藏版本,各位可以试一下:https://www.nuget.org/packages/Senparc.Weixin/4.16.5

lishewen commented 7 years ago

我这边抓到的包是 utf-8 的,是正确的,所以没法测试。。。@xuSs1994 你可以把 Senparc.Weixin 升级到 4.16.5 试试

JeffreySu commented 7 years ago

@xuSs1994 欢迎反馈结果,如果可以的话我们就发布到正式版本啦