You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the following code for subscription testing, but some unexpected situations occurred:
`using System;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet;
using MQTTnet.Client;
namespace ConsoleApp1
{
internal class Program
{
private static MqttClientOptions Options
{
get
{
MqttClientOptionsBuilder builder = new MqttClientOptionsBuilder();
builder.WithTcpServer("127.0.0.1", 6000);
builder.WithCleanSession(false);
var id = Guid.NewGuid().ToString("N");
builder.WithClientId(id);
return builder.Build();
}
}
static void Main()
{
Task.Run(async() =>
{
MqttFactory _mqttFactory = new MqttFactory();
IMqttClient _mqttClient = _mqttFactory.CreateMqttClient();
var result = await _mqttClient.ConnectAsync(Options, CancellationToken.None);
var options = _mqttFactory.CreateSubscribeOptionsBuilder().WithTopicFilter("Test").Build();
try
{
var task = await _mqttClient.SubscribeAsync(options, CancellationToken.None);
}
catch (Exception ex)
{
}
});
Console.ReadLine();
}
}
} The error message is as follows: System.ArgumentOutOfRangeException HResult=0x80131502 Message=索引超出范围。必须为非负值并小于集合大小。 Arg_ParamName_Name Source=mscorlib StackTrace: at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at MQTTnet.Client.MqttClientSubscribeResultFactory.CreateSubscribeResultItem(Int32 index, MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket) at MQTTnet.Client.MqttClientSubscribeResultFactory.Create(MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket) at MQTTnet.Client.MqttClient.<SubscribeAsync>d__47.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at ConsoleApp1.Program.<>c.<
b__2_0>d.MoveNext() in D:\Work\project\Tools\ConsoleApp1\ConsoleApp1\Program.cs:line 38
I used the following code for subscription testing, but some unexpected situations occurred:
`using System;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet;
using MQTTnet.Client;
namespace ConsoleApp1
{
internal class Program
{
private static MqttClientOptions Options
{
get
{
MqttClientOptionsBuilder builder = new MqttClientOptionsBuilder();
}
b__2_0>d.MoveNext() in D:\Work\project\Tools\ConsoleApp1\ConsoleApp1\Program.cs:line 38The error message is as follows: System.ArgumentOutOfRangeException HResult=0x80131502 Message=索引超出范围。必须为非负值并小于集合大小。 Arg_ParamName_Name Source=mscorlib StackTrace: at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at MQTTnet.Client.MqttClientSubscribeResultFactory.CreateSubscribeResultItem(Int32 index, MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket) at MQTTnet.Client.MqttClientSubscribeResultFactory.Create(MqttSubscribePacket subscribePacket, MqttSubAckPacket subAckPacket) at MQTTnet.Client.MqttClient.<SubscribeAsync>d__47.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()at ConsoleApp1.Program.<>c.<
此异常最初是在此调用堆栈中引发的:
System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument, System.ExceptionResource)
MQTTnet.Client.MqttClientSubscribeResultFactory.CreateSubscribeResultItem(int, MQTTnet.Packets.MqttSubscribePacket, MQTTnet.Packets.MqttSubAckPacket)
MQTTnet.Client.MqttClientSubscribeResultFactory.Create(MQTTnet.Packets.MqttSubscribePacket, MQTTnet.Packets.MqttSubAckPacket)
MQTTnet.Client.MqttClient.SubscribeAsync(MQTTnet.Client.MqttClientSubscribeOptions, System.Threading.CancellationToken)
ConsoleApp1.Program.Main.AnonymousMethod__2_0() (位于 Program.cs 中)
The text was updated successfully, but these errors were encountered: