Closed mridah closed 4 years ago
Hi, first of all your TCP server is wrong. It will not work with the prefix "http://" in it. I was not able to reproduce the issue with netstandard and regular .net framework.
But I got this exception on UWP. Are you building an UWP application?
@chkr1011 hi, no I'm working on normal .NET Framework 4.7.2. Not using UWP.
I'm getting the same error even after removing the protocol prefix. Any other suggestion ?
Please show me the output. I can see a little bit from it in the screenshot but is is cut off. It seems that another exception is thrown before the null ref exception happens.
Apart from that I have fixed this issue in latest master branch.
Hi @chkr1011 thanks for the fast reply. I checked it again. It's not throwing any error but it's just not connecting to the broker.
Please see the working on this Link
I am wondering if this can work at all. You have the connect method with a Task but you do not await it. Please try with .Wait() on the returning task. Apart from that it looks good to me.
Hey,
I changed the connection code from await client.ConnectAsync(options, CancellationToken.None);
to client.ConnectAsync(options, CancellationToken.None);
and it started working.
Maybe the handlers require the connection to be established beforehand.
No sorry I mean the call in your constructor. Not the connect method.
I have the same problem when I supply a wrong server address. I have the Mqttclient as a IHostedService in an ASP.NET app running dotnetcore3.1
public async Task StartAsync(CancellationToken cancellationToken)
{
try
{
await this.mqttClient.ConnectAsync(this.mqttClientOptions, cancellationToken);
}
catch (MqttCommunicationException e)
{
this.logger.LogWarning("Could not connect to MQTT Broker", e);
}
}
I get an NullReferenceException (which I cannot catch) when I use the debugger. The warning is logged.
As I said I tried to add another catch (Exception e)
to catch the NullRefence but this never logged anything.
Please try 3.0.10-rc1. The issue is fixed in that version.
Can confirm that the issue is fixed for me. Thank you!
Describe your question
I tried using the sample code provided with .NET framework, but I keep getting
System.NullReferenceException
onConnectAsync()
Which project is your question related to?
This is my code:
Am I doing something wrong ??? @chkr1011