Program Crashes on Debugging - c#

I am new to C# this is kind of my first program. I am trying to integrate a SOAPI from OVH.IE (more info here: www.ovh.ie/products/soapi.xml), but whenever I launch the program and click the login button the program crashes (memory usage of VS2012 increases and then crashes).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web.Services;
namespace Server_Manager
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}
void login(string uid, string pwd, string dc)
{
if (dc == "OVH")
{
managerService soapi = new managerService();
string session = soapi.login(uid, pwd, "ie", false);
if (String.IsNullOrWhiteSpace(session))
{
MessageBox.Show("Not Logged");
}
else
{
MessageBox.Show("Logged In");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(textBox1.Text) || String.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("Please Fill all the Details");
}
else
{
string uid, pwd, dc;
uid = textBox1.Text;
pwd = textBox2.Text;
dc = comboBox1.Text;
login(uid,pwd,dc);
}
MessageBox.Show(comboBox1.Text);
}
}
}

These instructions are for diagnosing this in WinDBG, a command line based debugger from microsoft, but I have been told they can work in Visual Studio.
Start up the application
Start up WinDBG and attach to the application
Type in ".loadby sos clr" (assuming >=4.0 framework)
Type "dumpheap -stat"
Look over the results, for suspicious objects type "dumpheap -mt {0}" where {0} is replaced by the objects MT address
If you don't know why objects are alive, type "gcroot {0}" passing an object address from above

Related

C# startup form unable to be shown

This is my first assignment using C# and I've learned briefly about programming with Python in my pre-u. The C# form that I would like to show the user upon logging in can't be shown and instead, the program displays the Built errors msg, where I click on 'Yes' to continue running the last successful build. However, it will show one of the previous forms (which I have deleted from the program) instead - making it hard for me to test run and check for any other errors in my program.
The form I would like to show is TechnicianHome.
Error
There were built errors. Would you like to continue and run the last successful build?
Any help is much appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ASSIGNMENT
{
public partial class TechnicianHome : Form
{
public static string name;
public TechnicianHome()
{
InitializeComponent();
}
public TechnicianHome (string n)
{
InitializeComponent();
name = n;
}
private void TechnicianHome_Load(object sender, EventArgs e)
{
lblWelcome.Text = "Welcome" + name;
}
private void button1_Click(object sender, EventArgs e)
{
ServiceRequests vr = new ServiceRequests();
this.Hide();
vr.ShowDialog();
}
private void button1_Click_1(object sender, EventArgs e)
{
UpdateProfile up = new UpdateProfile();
this.Hide();
up.ShowDialog();
}
}
}

Why I am coming across "Format Exception" while execution in C# TCP/IP Application?

The code is as follows:
The ServerForm Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SimpleTCP;
namespace TCPIP
{
public partial class ServerForm : Form
{
public ServerForm()
{
InitializeComponent();
}
SimpleTcpServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new SimpleTcpServer();
server.Delimiter = 0x13; //enter
server.StringEncoder = Encoding.UTF8;
server.DataReceived += Server_DataReceived;
}
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
e.ReplyLine(string.Format("You said: {0}",e.MessageString));
});
// throw new NotImplementedException();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void StartButton_Click(object sender, EventArgs e)
{
StatusText.Text += "Server Starting !";
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text)); //error here
server.Start(ip,Convert.ToInt32(PortText.Text));
}
private void StopButton_Click(object sender, EventArgs e)
{
if(server.IsStarted)
{
server.Stop();
}
}
}
}
The Code of the ClientForm is as follows:
using SimpleTCP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpClient client;
private void ConnectButton_Click(object sender, EventArgs e)
{
ConnectButton.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
client = new SimpleTcpClient();
client.StringEncoder = Encoding.UTF8;
client.DataReceived += Client_DataReceived;
}
private void Client_DataReceived(object sender, SimpleTCP.Message e)
{
StatusText.Invoke((MethodInvoker)delegate ()
{
StatusText.Text = e.MessageString;
//...
});
//throw new NotImplementedException();
}
private void SendButton_Click(object sender, EventArgs e)
{
client.WriteLineAndGetReply(TextMessage.Text, TimeSpan.FromSeconds(4));
}
}
}
The issue in the above code is that it is 'build'ing correctly and even when I am debug it with the new instance, the code is running fine, but will I debug, as soon as I press the "start" button in the Server form it shows the error in line :
System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(HostText.Text));
The error is: System.FormatException: 'Input string was not in a correct format.'
Please refer the Screenshot for details and suggest a potential fix to the issue.Image of Screenshot of Error inLine
Clearly HostText.Text is returning a value that can't be parsed into a long.
This exception is coming from long.Parse, which is really a language shortcut for Int64.Parse, whose documentation states that it will throw this exception if the input string is not formatted correctly.

C# Strongly typed dataset validation approach

I am trying to "learn" C# and building my 1st database driven data entry application. I am coming from Oracle development, hence wondering whether am doing few things right, as most of the examples I could find are dealing with datasets derived using SQL
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void l_PEOPLEBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
if ((string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text) || (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text) ||
(string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text)))))
{
MessageBox.Show("Error, one of the mandatory columns are not filled up");
return;
}
try
{
this.Validate();
this.pERSON_IDTextBox.Text = this.l_PEOPLETableAdapter.ScalarQuery().ToString();
this.l_PEOPLEBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.uNUDataSet);
}
catch (Exception ex)
{
MessageBox.Show("Exception happened, original message: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'uNUDataSet.L_PEOPLE' table. You can move, or remove it, as needed.
this.l_PEOPLETableAdapter.Fill(this.uNUDataSet.L_PEOPLE);
// this.fIRST_NAMETextBox.Focus();
this.ActiveControl = this.fIRST_NAMETextBox;
}
private void sByName_Click(object sender, EventArgs e)
{
this.l_PEOPLETableAdapter.FillByNAME(this.uNUDataSet.L_PEOPLE, this.sByNameText.Text);
}
private void fIRST_NAMETextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text))
{
eNROLL_errorprovider.SetError(fIRST_NAMETextBox, "Name required");
fIRST_NAMETextBox.Focus();
}
}
private void cIVIL_IDTextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text))
{
eNROLL_errorprovider.SetError(cIVIL_IDTextBox, "Civil ID Number required");
cIVIL_IDTextBox.Focus();
}
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text))
{
eNROLL_errorprovider.SetError(tELEPHONE_NUMBERTextbox, "Telephone Number required");
tELEPHONE_NUMBERTextbox.Focus();
}
else
{
eNROLL_errorprovider.Clear();
}
}
}
}
What I am trying to do with the above piece of code is, unless the user enters first name, civil id number and supply the telephone number, the form shouldn't submit the data. For the person id, I am using a sequence, called through a scalar query attached to the table adaptor.
While I click the binding navigator save button, what should execute in order to fire the validation events attached with the text columns so that the error provider will get activated?
You need to register the event like the code below
public Form1()
{
InitializeComponent();
tELEPHONE_NUMBERTextbox.Validated += new EventHandler(tELEPHONE_NUMBERTextbox_Validated);
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
}

messagebox.show error/ no overload for method 'show' takes 1 arguments

I'm trying to show a MessageBox but i'm getting the error:
no overload for method 'show' takes 1 arguments.
I cant seem to find a solution in any forum (stackoverflow,msdn...) and I have tried everything that has been suggested. What am I missing?
Any help is appreciated.
BTW. I'm new to windows forms and c# in general but I have written this from a tutorial and it should work.
This is the complete code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetworksApi.TCP.CLIENT;
using System.IO;
namespace AdvancedClientChat
{
public partial class Form1 : Form
{
Client client;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnConnect_Click(object sender, EventArgs e)
{
if (textBoxIP.Text !="" && textBoxName.Text !="" && textBoxPort.Text !="")
{
client = new Client();
client.ClientName = textBoxName.Text;
client.ServerIp = textBoxIP.Text;
client.ServerPort = textBoxPort.Text;
}
else
{
MessageBox.Show("You must fill all the boxes");
}
}
private void btnSend_Click(object sender, EventArgs e)
{
}
private void MessageBox_KeyDown(object sender, KeyEventArgs e)
{
}
}
}
It looks like you have a control named MessageBox which is causing your problems. Either rename the control, or you will have to specify the MessageBox class with its full namespace, System.Windows.Forms.MessageBox.Show("myMessage");
private void btnConnect_Click(object sender, EventArgs e)
{
if (textBoxIP.Text !="" && textBoxName.Text !="" && textBoxPort.Text !="")
{
client = new Client();
client.ClientName = textBoxName.Text;
client.ServerIp = textBoxIP.Text;
client.ServerPort = textBoxPort.Text;
}
else
{
System.Windows.Forms.MessageBox.Show("You must fill all the boxes");
}
}

MS Access to C# connection Visual Studio 13.. can't find what is wrong?

It is giving system.collections.listdictionaryinternal error, but can't figure out why. I have followed a video on youtube for this code and the tutor had written the same code and it was executed properly. Please help
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace SundayApp
{
public partial class Form1 : Form
{
OleDbConnection con = new oleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\users\owner\searches\documents\visual studio 2013\Projects\SundayApp\SundayApp\Sunday.accdb");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con.Open();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string s = string.Format("INSERT into studentinfo values {0},{1}", textBox1.Text, textBox2.Text);
OleDbCommand c = new OleDbCommand(s, con);
try { c.ExecuteNonQuery(); }
catch (Exception ee) { MessageBox.Show( ee.Data); }
MessageBox.Show("Data Added");
c.Dispose();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
Your SQL syntax appears to be missing the parenthesis around the value arguments.
string s = string.Format("INSERT into studentinfo values ({0},{1})", textBox1.Text, textBox2.Text);
If this is not it, can you please post the stack trace, so we can see what line is generating the error. Thanks.

Categories

Resources