MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

Retained Message is not saved, if publishing using MqttHostedServer

Open chris1705 opened this issue 8 years ago • 1 comments

Hello Christian,

I think I found a little bug in your project. When I publish a retained message trough the MqttHostedServer it throws the following exception:

>> [2018-02-20T20:31:18.3906896+01:00] [3] [MqttClientSessionsManager] [Error]:
Error while processing application message
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
   at MQTTnet.Server.MqttClientSessionsManager.InterceptApplicationMessage(MqttC
lientSession senderClientSession, MqttApplicationMessage applicationMessage)
   at MQTTnet.Server.MqttClientSessionsManager.<DispatchApplicationMessageAsync>
d__29.MoveNext()

My code looks like this:

var mqttServer = app.ApplicationServices.GetRequiredService<IMqttServer>();
var register = app.ApplicationServices.GetRequiredService<PlayerRegister>();

var response = JsonConvert.SerializeObject(register.GetPlayers());
mqttServer.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("mmm/master/known-players").WithPayload(response).WithRetainFlag(true).Build());

Do you have an idea why it's not working? Thanks a lot!

Regards Chris

chris1705 avatar Feb 20 '18 19:02 chris1705

Hi @chris1705, thanks for sharing this issue. Do you maybe have some code in the application message interception callback? It is also possible that you share the complete trace (described in Wiki)? On my machine I cannot reproduce it.

Best regards Christian

chkr1011 avatar Feb 21 '18 19:02 chkr1011