Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1286
  • Last Modified:

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
0
AZZA-KHAMEES
Asked:
AZZA-KHAMEES
  • 7
  • 6
1 Solution
 
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
 
Meir RivkinFull stack Software EngineerCommented:
can u debug the code?
is the SmppClient client instance is null?
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
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
 
Meir RivkinFull stack Software EngineerCommented:
try use the 2nd SendMessage function where u pass timeout value:
client.SendMessage(textMsg, 1000);

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now