Object reference not set to an instance of an object.

i created a sample project to try Jamaa SMPP, but when i run the code i am getting this error in the last line
Object reference not set to an instance of an object.

protected void Page_Load(object sender, EventArgs e)
        {
            SmppClient client = new SmppClient();
            SmppConnectionProperties properties = client.Properties;
            properties.SystemID = "username";
            properties.Password = "password";
            properties.Port = 3333; 
            properties.Host = "xxx.xxx.xxx.xxx";
            properties.SystemType = "";
            properties.DefaultServiceType = "xxx";
      
            client.AutoReconnectDelay = 3000;

            client.KeepAliveInterval = 15000;

            client.Start();

            //--send SMS
            TextMessage textMsg = new TextMessage();
            textMsg.Text = "Hello, this is my message!";
            textMsg.DestinationAddress = "99999999";
            textMsg.SourceAddress = "888888888";
          
            client.SendMessage(textMsg);
        }

Open in new window


please help
LVL 1
AZZA-KHAMEESAsked:
Who is Participating?
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
try use the 2nd SendMessage function where u pass timeout value:
client.SendMessage(textMsg, 1000);

Open in new window

0
 
Meir RivkinFull stack Software EngineerCommented:
this line?
 client.SendMessage(textMsg);

Open in new window

0
 
AZZA-KHAMEESAuthor Commented:
thank you for the reply, yes so how can i solve it?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Meir RivkinFull stack Software EngineerCommented:
can u debug the code?
is the SmppClient client instance is null?
0
 
AZZA-KHAMEESAuthor Commented:
fro where i can know if its null or not?
0
 
Meir RivkinFull stack Software EngineerCommented:
if you can debug the code and reproduce the exception every time then simply check if client is null.
also, u can add code which checks if the client is null.
i'd also use try/catch to detect what and where the error occur:
protected void Page_Load(object sender, EventArgs e)
        {try{
            SmppClient client = new SmppClient();
            SmppConnectionProperties properties = client.Properties;
            properties.SystemID = "username";
            properties.Password = "password";
            properties.Port = 3333; 
            properties.Host = "xxx.xxx.xxx.xxx";
            properties.SystemType = "";
            properties.DefaultServiceType = "xxx";
      
            client.AutoReconnectDelay = 3000;

            client.KeepAliveInterval = 15000;

            client.Start();

            //--send SMS
            TextMessage textMsg = new TextMessage();
            textMsg.Text = "Hello, this is my message!";
            textMsg.DestinationAddress = "99999999";
            textMsg.SourceAddress = "888888888";
          if(client != null){
            client.SendMessage(textMsg);
}else{
//log error to file or raise error
}
}catch(exception ex){
//log exception to file or raise error
}
        }

Open in new window

0
 
AZZA-KHAMEESAuthor Commented:
i tried your segusstion and i am getting the following error in catch

System.NullReferenceException: Object reference not set to an instance of object
at JamaaTech.Smpp.Net.Client.SmppClient.SendMessage(ShortMessage masage)
0
 
Meir RivkinFull stack Software EngineerCommented:
which line?
0
 
AZZA-KHAMEESAuthor Commented:
the error shows in line
client.SendMessage(textMsg)

Open in new window


which mean its pass the if statement
0
 
Meir RivkinFull stack Software EngineerCommented:
try replace textMsg with string.Empty, is it still throwing exception?
0
 
AZZA-KHAMEESAuthor Commented:
yes still
0
 
Meir RivkinFull stack Software EngineerCommented:
the problem is in the implementation of SendMessage function.
do u have the source of SmppClient ?
0
 
AZZA-KHAMEESAuthor Commented:
SmppClient is dll file i download it from

CodePlex
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.