0

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: Error message Screenshot

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".

Camilo Terevinto
  • 26,697
  • 6
  • 67
  • 99
Gewoo
  • 337
  • 4
  • 17
  • It's missing the file. Are you sure the file is in your solution's folder (probably inside the debug folder?) – JustAPup Jan 05 '16 at 18:17
  • @Minh Yes it is this are all the files in my debug folder: http://prntscr.com/9mgksg – Gewoo Jan 05 '16 at 18:22
  • Try rebuilding your whole solution, or closing and opening VS again. Also, where exactly is it throwing this error? – JustAPup Jan 05 '16 at 18:44
  • The error is also raised when one of the DLL's that WhatAppApi requires can't be found. That's what the "or one of it's dependencies" means. Run the Fusion Log Viewer (fuslogvw.exe) as Administrator and enabled logging. Then run your program. Refresh the log viewer and it should give you a more detailed error. To find fuslogvw.exe - http://stackoverflow.com/questions/1674279/cant-locate-fuslogvw-exe-on-my-machine. – shf301 Jan 05 '16 at 21:52

0 Answers0