Link to home
Start Free TrialLog in
Avatar of AZZA-KHAMEES
AZZA-KHAMEESFlag for Bahrain

asked on

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
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

this line?
 client.SendMessage(textMsg);

Open in new window

Avatar of AZZA-KHAMEES

ASKER

thank you for the reply, yes so how can i solve it?
can u debug the code?
is the SmppClient client instance is null?
fro where i can know if its null or not?
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

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)
which line?
the error shows in line
client.SendMessage(textMsg)

Open in new window


which mean its pass the if statement
try replace textMsg with string.Empty, is it still throwing exception?
yes still
the problem is in the implementation of SendMessage function.
do u have the source of SmppClient ?
SmppClient is dll file i download it from

CodePlex
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial