Solved

Object reference not set to an instance of an object.

Posted on 2013-06-11
13
1,182 Views
Last Modified: 2013-06-13
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
Comment
Question by:AZZA-KHAMEES
  • 7
  • 6
13 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39240219
this line?
 client.SendMessage(textMsg);

Open in new window

0
 

Author Comment

by:AZZA-KHAMEES
ID: 39240282
thank you for the reply, yes so how can i solve it?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39240284
can u debug the code?
is the SmppClient client instance is null?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39241216
fro where i can know if its null or not?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39241311
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
 

Author Comment

by:AZZA-KHAMEES
ID: 39243483
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 42

Expert Comment

by:sedgwick
ID: 39243559
which line?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243607
the error shows in line
client.SendMessage(textMsg)

Open in new window


which mean its pass the if statement
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243609
try replace textMsg with string.Empty, is it still throwing exception?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243618
yes still
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243628
the problem is in the implementation of SendMessage function.
do u have the source of SmppClient ?
0
 

Author Comment

by:AZZA-KHAMEES
ID: 39243692
SmppClient is dll file i download it from

CodePlex
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39243726
try use the 2nd SendMessage function where u pass timeout value:
client.SendMessage(textMsg, 1000);

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are anything like me, you install many apps on your phone and have your life on it, sometimes literally.  When I bought my current phone, a Samsung Galaxy S5 from Verizon, they were only selling the versions with 16 GB internal.  I didn't rea…
I'm Dumb-phoned(ed) Last week, I noticed this message when adding events to my Google Calendar: On June 27th (2015), Google is removing SMS as a notification option for Google Calendar events.  Their assumption is that enough people have smart p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now