none
error while getting an serialised object via binary stream RRS feed

  • Question

  • Hello All,

    General Scenario

    I've been coding a simple chat application. It is supposed to transfer some data from FrontEnd Client (connected to Client's UI) to BackEndClient (created automatically by the chat's Server) via tcp protocol.

    Fine.

    One typo of the messages is some Connected Message, it includes all the relevant data about the User.

    The Error

    When I try to decerialise the firs message and to check if it is a connected message...

     public void WaitForHandshake()
            {
                _waitForHandshake = new Thread(() =>
                {
                     connectedMessage = _formatter.Deserialize(_stream) as ConnectedMessage;
                    if (connectedMessage == null)
                    {
                        OnHandshakeFail();
                       
                    }
                    _user = connectedMessage.user;
                   
                   ...
                });
                _waitForHandshake.IsBackground = true;
                _waitForHandshake.Start();
            }

    And on the line connectedMessage = _formatter.Deserialize(_stream) as ConnectedMessage; I've got a big punch into my face, since I am told that 

    An unhandled exception of type 'System.NullReferenceException' occurred in ChatBasicSample.BL.dll

    Where I am wrong with my code?


    40yo novice

    Saturday, October 25, 2014 11:46 AM

Answers

  • Make sure you have initialize formatter and stream object i.e. check that formatter or _stream variables are not null. You can debug your application and make sure WaitForHandShake is called after above variables has some non-null values.

    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Saturday, October 25, 2014 12:57 PM