Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do I encounter anomalies when subscribing #2088

Open
MuYangRenHR opened this issue Sep 30, 2024 · 0 comments
Open

Why do I encounter anomalies when subscribing #2088

MuYangRenHR opened this issue Sep 30, 2024 · 0 comments
Labels
question It is a question regarding the project

Comments

@MuYangRenHR
Copy link

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

此异常最初是在此调用堆栈中引发的:
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 中)

**Thank you for providing assistance**
@MuYangRenHR MuYangRenHR added the question It is a question regarding the project label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is a question regarding the project
Projects
None yet
Development

No branches or pull requests

1 participant