hey guys i tried to make whatsapp sender using c# this is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Net.Sockets;
using System.Net.WebSockets;
using WhatsAppApi.Register;
using WhatsAppApi.Account;
using WhatsAppApi;
using WhatsAppApi.Response;
namespace CommunicationSourcesWithThirdPartyApps
{
class Program
{
public static string name;
public static string message;
public static string password;
public static string to;
public static string phoneNumber;
static void Main(string[] args)
{
WhatsApp wa = new WhatsApp(phoneNumber, password, name, true);
Console.WriteLine("Enter your phone number: ");
phoneNumber = Console.ReadLine();
Console.WriteLine("Enter your name: ");
name = Console.ReadLine();
Console.WriteLine("Enter your message: ");
message = Console.ReadLine();
Console.WriteLine("Where to send the message: ");
to = Console.ReadLine();
password = WhatsRegisterV2.GetToken(phoneNumber);
wa.OnConnectSuccess += () =>
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Connected...");
wa.OnLoginSuccess += (phone, data) =>
{
Console.WriteLine("Login success!");
wa.SendMessage(to, message);
Console.WriteLine("Message Sent!");
};
wa.OnLoginFailed += (data) =>
{
Console.WriteLine("Login failed!");
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
Console.WriteLine("Connection Failed!");
};
wa.Connect();
Console.ReadLine();
}
}
}
and im getting error at -wa.Login();- Object reference not set to an instance of an object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Net.Sockets;
using System.Net.WebSockets;
using WhatsAppApi.Register;
using WhatsAppApi.Account;
using WhatsAppApi;
using WhatsAppApi.Response;
namespace CommunicationSourcesWithThirdPartyApps
{
class Program
{
public static string name;
public static string message;
public static string password;
public static string to;
public static string phoneNumber;
static void Main(string[] args)
{
WhatsApp wa = new WhatsApp(phoneNumber, password, name, true);
Console.WriteLine("Enter your phone number: ");
phoneNumber = Console.ReadLine();
Console.WriteLine("Enter your name: ");
name = Console.ReadLine();
Console.WriteLine("Enter your message: ");
message = Console.ReadLine();
Console.WriteLine("Where to send the message: ");
to = Console.ReadLine();
password = WhatsRegisterV2.GetToken(phoneNumber);
wa.OnConnectSuccess += () =>
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Connected...");
wa.OnLoginSuccess += (phone, data) =>
{
Console.WriteLine("Login success!");
wa.SendMessage(to, message);
Console.WriteLine("Message Sent!");
};
wa.OnLoginFailed += (data) =>
{
Console.WriteLine("Login failed!");
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
Console.WriteLine("Connection Failed!");
};
wa.Connect();
Console.ReadLine();
}
}
}
and im getting error at -wa.Login();- Object reference not set to an instance of an object.



![[Image: UylCjc.png]](https://www.talkimg.com/images/2026/05/03/UylCjc.png)
