So, I'm making a simple chatbot, but when I try to attach it to skype by a button, it just crashes with an overflow, I was following a tutorial and did everything in the tutorial, but it just crashes when I press the attach button. Idk why since it seems to work for everyone else who uses the Skype4COM.dll
private void Form1_Load(object sender, EventArgs e)
{
}
private void materialRaisedButton1_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
public Skype MySkype
{
get => MySkype;
set => MySkype = value;
}
private void materialFlatButton1_Click(object sender, EventArgs e)
{
MySkype.Attach(5, false);
MessageBox.Show("Process Atached " + MySkype.CurrentUserHandle);
}
}
}
You're receiving a StackOverflow exception because the get
and set
accessors reference the property rather than the private field you should have created; in essence, this causes an endless recursive loop that eventually causes the process to exhaust the available RAM.
your property should be something like this:
public Skype MySkype
{
get => _mySkype;
set => _mySkype = value;
}
You should always aim to name private fields with an _
prefix to distinguish them from properties.
Another approach would just be:
Skype MySkype { get; set; }