被动回复模块 后台报Failed to compare two elements in the array.
微信开发
· y978527977
· 查看 892 次
· 于 225天前
环境:.net6 WebApi
报错信息:
[2024-02-02 16:52:33] [Error] [Microsoft.AspNetCore.Server.Kestrel] : Connection id "0HN13PGB71KF8", Request id "0HN13PGB71KF8:00000002": An unhandled exception was thrown by the application.System.InvalidOperationException: Failed to compare two elements in the array.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Senparc.Weixin.Tencent.WXBizMsgCrypt.DictionarySort.Compare(Object oLeft, Object oRight)
at System.Array.SorterObjectArray.InsertionSort(Int32 lo, Int32 hi)
at System.Array.SorterObjectArray.IntroSort(Int32 lo, Int32 hi, Int32 depthLimit)
at System.Array.SorterObjectArray.IntrospectiveSort(Int32 left, Int32 length)
--- End of inner exception stack trace ---
at System.Array.SorterObjectArray.IntrospectiveSort(Int32 left, Int32 length)
at System.Array.Sort(Array keys, Array items, Int32 index, Int32 length, IComparer comparer)
at System.Collections.ArrayList.Sort(Int32 index, Int32 count, IComparer comparer)
at Senparc.Weixin.Tencent.WXBizMsgCrypt.GenarateSinature(String sToken, String sTimeStamp, String sNonce, String sMsgEncrypt, String& sMsgSignature)
at Senparc.Weixin.Tencent.WXBizMsgCrypt.VerifySignature(String sToken, String sTimeStamp, String sNonce, String sMsgEncrypt, String sSigture)
at Senparc.Weixin.Tencent.WXBizMsgCrypt.DecryptMsg(String sMsgSignature, String sTimeStamp, String sNonce, String sPostData, String& sMsg)
at Senparc.Weixin.MP.MessageHandlers.MessageHandler`1.Init(XDocument postDataDocument, IEncryptPostModel postModel)
at Senparc.NeuChar.MessageHandlers.MessageHandler`3.CommonInitialize(XDocument postDataDocument, Int32 maxRecordCount, IEncryptPostModel postModel, Boolean onlyAllowEncryptMessage, IServiceProvider serviceProvider)
at Senparc.NeuChar.MessageHandlers.MessageHandler`3..ctor(Stream inputStream, IEncryptPostModel postModel, Int32 maxRecordCount, Boolean onlyAllowEncryptMessage, IServiceProvider serviceProvider)
at Senparc.Weixin.MP.MessageHandlers.MessageHandler`1..ctor(Stream inputStream, PostModel postModel, Int32 maxRecordCount, Boolean onlyAllowEncryptMessage, DeveloperInfo developerInfo, IServiceProvider serviceProvider)
at JWTTest.Core.Service.CustomMessageHandler..ctor(Stream inputStream, PostModel postModel, Int32 maxRecordCount, Boolean onlyAllowEncryptMessage, IServiceProvider serviceProvider) in E:\项目文件\博客\Core\Service\CustomMessageHandler.cs:line 52
at JWTTest.Controllers.PublicController.Post(PostModel postModel) in E:\项目文件\博客\Controllers\PublicController.cs:line 153
at lambda_method6(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
源代码:
messageHandler = new CustomMessageHandler(await Request.GetRequestMemoryStreamAsync(), postModel, maxRecordCount);//接收消息(第一步)
public CustomMessageHandler(Stream inputStream, PostModel postModel, int maxRecordCount = 0, bool onlyAllowEncryptMessage = false, IServiceProvider serviceProvider = null)
: base(inputStream, postModel, maxRecordCount, onlyAllowEncryptMessage, serviceProvider: serviceProvider)
{
//这里设置仅用于测试,实际开发可以在外部更全局的地方设置,
//比如MessageHandler<MessageContext>.GlobalGlobalMessageContext.ExpireMinutes = 3。
GlobalMessageContext.ExpireMinutes = 3;
OnlyAllowEncryptMessage = true;//是否只允许接收加密消息,默认为 false
}
跟示例代码一毛一样的,我什么都没动只是改了下配置