I am trying to send whatsapp messages with C# but I get a strange error.
My code:
namespace Whap
{
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
//Send message
string from = "myPhoneNumber";
string to = toTxt.Text;
string msg = msgTxt.Text;
WhatsApp wa = new WhatsApp(from, "myWhatsAppAccountCode", "Nick", false, false);
wa.OnConnectSuccess += () =>
{
statusLabel.Text = "Connecting to Whatsapp...";
wa.OnLoginSuccess += (phoneNumber, data) =>
{
wa.SendMessage(to, msg);
statusLabel.Text = "Message sent";
};
wa.OnLoginFailed += (data) =>
{
statusLabel.Text = "Login Failed: " + data;
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
statusLabel.Text = "Connection Failed";
};
wa.Connect();
}
}
}
But when I try to send a message I get this error:
Translated to English:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in System.Windows.Forms.dll
Additional information: Could not load file or assembly WhatsAppApi, Version=1.0.2.1, Culture=EN-us, PublicKeyToken=null or one of its dependencies. The system cannot find the file specified.
I think the error is because it can't find the WhatsAppApi dll file, but I'm not sure and I have no idea how I can fix it, in the WhatsAppApi properties in the solution explorer I have "Copy Local: True".