Not logged in. · Lost password · Registration disabled
Forum: MatriX and XmppDotNet RSS
Avatar
sldr #1
Subject: I got a NullReferenceException in XmppXElementStreamObserver.Where
Here is logging with call stack:
info: EMailIM.Program[0]
      SEND: 
info: EMailIM.Program[0]
      RECV: <message type="chat" id="purplee653b8bd" to="sldr@XXX.XXXXX.com" from="jonesds@XXX.XXXXX.com/4a10bc09"><composing xmlns="http://jabber.org/protocol/chatstates"/></message>
info: EMailIM.Program[0]
      RECV: <message type="chat" id="purplee653b8be" to="sldr@XXXXXXXXX.com" from="jonesds@XXXXXXXXX.com/4a10bc09"><active xmlns="http://jabber.org/protocol/chatstates"/><body>ping</body></message>
info: EMailIM.Program[0]
      RECV: <message type="chat" id="purplee653b8bf" to="sldr@XXXXXXXXX.com" from="jonesds@XXXXXXXXX.com/4a10bc09"><active xmlns="http://jabber.org/protocol/chatstates"/></message>
warn: DotNetty.Transport.Channels.DefaultChannelPipeline[0]
      An ExceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
System.NullReferenceException: Object reference not set to an instance of an object.
   at EMailIM.Program.<>c.<SetupSubscribes>b__11_0(XmppXElement el) in C:\Users\derudder\Documents\Visual Studio 2017\Projects\EMailIMPreRelease\Program.cs:line 176
   at System.Reactive.Linq.ObservableImpl.Where`1._.OnNext(TSource value)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Reactive.Stubs.<>c.<.cctor>b__2_1(Exception ex)
   at System.Reactive.AnonymousSafeObserver`1.OnError(Exception error)
   at System.Reactive.Linq.ObservableImpl.Where`1._.OnNext(TSource value)
   at System.Reactive.Observer`1.OnNext(T value)
   at Matrix.Network.Handlers.XmppStreamEventHandler.ChannelRead0(IChannelHandlerContext ctx, XmlStreamEvent msg)
   at DotNetty.Transport.Channels.SimpleChannelInboundHandler`1.ChannelRead(IChannelHandlerContext ctx, Object msg)
   at DotNetty.Transport.Channels.AbstractChannelHandlerContext.InvokeChannelRead(Object msg)
info: EMailIM.Program[0]
      SEND:

The first line is line 176:
  1.       x.XmppXElementStreamObserver.Where(el => el.OfType<Message>() && el.Cast<Message>().Chatstate == Chatstate.Active && el.Cast<Message>().Body.Length > 0).Subscribe(el =>
  2.       {
  3.         Message m = el.Cast<Message>();
  4.         Log("Message:", el.ToString());
  5.         SendEMail(m.From, m.Body);
  6.       });

The program had been running fine for a day or so. I understand this is a prerelease so I understand if the last update for the logging I added broke something. Thanks for any help.

Laters,
SLDR
(Stephen L. De Rudder)
Avatar
sldr #2
Sorry for wasting your time.

Body is null so Body.Length is NullReferenceException.

I don't know why I didn't notice that.

SLDR
Avatar
Alex #3
In reply to post #1
You call Length on Body, but you do not have a null check on Body.
Your code is causing a crash on messages with no Body.

Alex