|
That didn't seem to make much difference - it still runs in debug without the DEBUG constant.
But I discovered another really weird issue. As explained before I get an unhandled exception when I execute the release .exe file, but if I run the the application in release mode inside Visual Studio(VS) I don't get the exception.
It seems that somehow VS has an influence on the release runtime. Also a fellow coworker experienced the same problem with another application, but with the debug .exe file.
Does VS set up some special runtime environment that prevents unhandled exceptions?
|
|
|
|
|
You might want to post what the exact exception was.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It is a TypeInitializationException with the inner exception NullReferenceException - and why it is thrown only in the release version run outside VS is my big mystery. If I run the debug .exe file outside VS it doesn't throw anything.
|
|
|
|
|
Question: if you have a multi-project solution, did you add project references or assembly references? If you use assembly references (for projects in your solution), that can be a big problem since your release build will use assemblies from your debug build (or vice versa). If you added a new type and did a release build, this type would not be in the debug build of your assembly.
So, remove your assembly references for projects in your solution. Then re-add them by right-clicking on your project, select Add Reference, then click on the Projects tab and select the right projects. This makes sure that everything is kept in sync and sets up build dependencies as well.
When you run the application, everything should work fine. If you maintain a build directory for other developers, make sure that you copy all of the assemblies from the same build configuration into that build directory.
We have a very large solution (I have about 60 projects in mine, being the build master), many of which are late-bound. Using these guidelines it's pretty easy to make sure everything is correct.
Also make sure that if you have late-bound assemblies (like for a plug-in style application) that you either keep the assembly version the same or update your app's .config file using assembly version redirection. You can find more about that by reading Redirecting Assembly Versions[^] in the .NET Framework SDK. We also do this for ours so we don't have to re-deploy every assembly with updates to our application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for the reply, but alas to no avail - all my references are added as you describe above.
The world of VS is a cruel place 
|
|
|
|
|
Heureka! - the bug has been found.
It was a Singleton issue.
I had a Singleton class like the following:
private static readonly IOServiceAgent instance = new IOServiceAgent();<br />
<br />
private IOServiceAgent(){}<br />
<br />
public static IOServiceAgent Instance<br />
{<br />
get<br />
{<br />
return instance;<br />
}<br />
}
Changed it to the following:
private static IOServiceAgent instance;<br />
<br />
private IOServiceAgent(){}<br />
<br />
public static IOServiceAgent Instance<br />
{<br />
get<br />
{<br />
if(instance == null)<br />
{<br />
instance = new IOServiceAgent();<br />
}<br />
<br />
return instance;<br />
}<br />
}
Somehow the first solution failed even though the property wasn't called prior to the exception throw.
Anyway thanks for the replys
-spif2001
|
|
|
|
|
I created a windows form. I added a SQLConnection, a SQLDataAdaptor, a DataSet all via the designer. I then added a TextBox and a ListBox and databound them both to a column in the DataSet. I then added a button that will show the next record with the following code;
this.BindingContext[this.dsPeople1.People].Position ++;
When I run this the ListBox’s selected line moves to the next record but the TextBox stays on the first record. Am I missing something?
This is the code that has been generated for the TextBox and the ListBox.
this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsPeople1, "People.First_Name"));
this.listBox1.DataSource = this.dsPeople1.People;
this.listBox1.DisplayMember = "First_Name";
John
|
|
|
|
|
It all depends on how you bind. Notice that the textBox1 's DataBindings binds to this.dsPeople1 , not this.dsPeople1.People like the listBox1 . Your binding expression, this.BindingContext[this.dsPeople1.People] also binds against People . These are very different. A BindingContext must use the exact same binding. this.dsPeople1 and this.dsPeople1.People are different contexts.
So, change the binding for textBox1 to this:
this.text1.DataBindings.Add(
new Binding("Text", this.dsPeople1.People, "First_Name"));
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply.
I tried that and I get the error;
"Cannot create a child list for field People."
This code is generated automatically when you set up the data binding for the textbox in the designer so should be okay, right???
John.
|
|
|
|
|
You got that error where?
If you actually read the documentation for the Control.BindingContext , it clearly states what I said - the binding context must be the same as what was used to bind the control. For your TextBox in question, they are not the same.
You could also try changing the binding for your ListBox to what the TextBox uses and changing your BindingContext accordingly as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The full error is:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll<br />
<br />
Additional information: Cannot create a child list for field People.
I single stepped through the program and the error happens after this line of code runs (every line of code in the Form1 constructor steps through okay but it fails when the last line has been executed and it returns to this line. If I break into it is breaks on the line after this one - int i = 0 ).
Application.Run(new Form1());
I read the documentation. Can you get it to work using the designer interface? Or even via code?
John.
|
|
|
|
|
You are right! When I tried your solution the first time I changed the second parameter but not the third. When I made both changes it worked.
So it looks like a bug in the designer. When I set the DataBindings in the property window of the TextBox it generates code the incorrect way. So now I am not binding that way but via my own code.
Thanks for your help.
John.
|
|
|
|
|
Hi there,
I am attempting to add a calculation via text box's?....unfortunately I am having no luck, has anybody got a sample code in calculating numbers/data ect... please help.
cheers
SM
|
|
|
|
|
I didn't get you properly.Please make it little clear.
Sreejith S S Nair
|
|
|
|
|
Hi Sreejith
I am building a new application where i want to add labour + material costs and I need to calculate those two items to equal in a seperate text box. I am using Microsoft Visual studio to assist me, but I don't really know how to use the properties section that well.
all i wan't to do is add two data types together and recieve a result whilst the application is live?
cheers
SM
|
|
|
|
|
for eg you are getting the two required values in a textbox then system will treat that values as string.so what you want to do first is, convert the two textbox values into numeric form.for eg. int or float or anything.
int labourcost=int.parse(textbox1.text);
int materialcost=int.parse(textbox2.text);
now you have numeric types of your input.
next is
resulttextbox.text=(labourcost+materialcost).ToString();
is this fine.
Sreejith S S Nair
|
|
|
|
|
A minor addition to the previous post by Sreejith:
As your TextBoxes can contain anything other than the string representation of a number, you should handle the FormatException of the Parse method.
<br />
try<br />
{<br />
int labour = int.Parse(textboxLabour.Text);<br />
int material = int.Parse(textboxMaterial.Text);<br />
}<br />
catch (System.FormatException)<br />
{<br />
}<br />
|
|
|
|
|
thanks dear
Sreejith S S Nair
|
|
|
|
|
Never mind
Let's hope stevemasters22 got what he wanted.
|
|
|
|
|
Hi Stefan,
I cant get it working...below is the code....pls help...all I wan't is for textbox3 to = textbox1 + textbox2, when i tab to textbox 3.
SM
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(184, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(112, 104);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
try
{
int labour = int.Parse(textBox1.Text);
int material = int.Parse(textBox2.Text);
textBox3.Text =textBox1+textBox2.ToString();
}
catch (System.FormatException)
{
//handle exceptions by assigning default values for example
}
}
}
}
|
|
|
|
|
The problem is your using the TextChanged event of TextBox3. Don't...don't use TextBox3 events to fire off the calculation. What you should be doing is performing the calculation on the Leave or LostFocus events of the other two TextBoxes. With a little modification to the TextBox properties, you could even use the Validating event. In any case, when you hanlde any of these events, you can do some validation on Textbox1 and Textbox2 so you can make sure that your not trying to add '100 + whoknowswhat'. Then all you do is Total = Decimal.Parse(Textbox1.Text) + Decimal.Parse(Textbox2.Text), then Textbox3.Text = Total.ToString().
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave,
I cant work it out chief, I am too much of a beginner(bloody hopeless)....could you pls show me a sample.
cheers
SM
|
|
|
|
|
You'll have to wait until I get home to put this sample together. I can't install the Framework and/or VS.NET on any machine here at work for security reasons...
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
 [EDIT]
I've reposted this because I found a couple typos after I posted it...
OK. Here's the modified sample. Warning!!!! This is COMPLETELY UNTESTED CODE!
I'm still at work, with nothing much else to do and wrote this from memory using Notepad of all things!
But, Stephan is right about experimenting with the events. Just try writing code for the various event handlers. It doesn't have to be anything special, maybe just displaying a descriptive MsgBox when the event handler is called.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
public class Form1 : System.Windows.Forms.Form
{
Single m_Labour = 0.0;
Single m_Material = 0.0;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.textBox1.Location = new System.Drawing.Point(64, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
this.textBox2.Location = new System.Drawing.Point(184, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
this.textBox2.Leave += new System.EventHandler(this.textBox2_Leave);
this.textBox3.Location = new System.Drawing.Point(112, 104);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
m_Labour = ValidateInput(textbox1);
textbox1.Text = m_Labour.ToString("##,###.00");
UpdateTotalTextBox();
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
m_Material = ValidateInput(textbox2);
textbox2.Text = m_Material.ToString("##,###.00");
UpdateTotalTextBox();
}
private Single ValidateInput(ref TextBox textboxToValidate)
{
Single returnValue;
try
{
returnValue = Single.Parse(textboxToValidate.Text);
}
catch (Exception e)
{
returnValue = 0;
}
return returnValue;
}
private void UpdateTotalTextbox()
{
Single jobTotal = m_Labour + m_Material;
textBox3.Text = jobTotal.ToString("##,###.00");
}
}
}
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As Dave said, it's wrong to use the TextChanged event of textBox3, cause this one is fired when its text changes, what means that your result changes.
Instead add event handler for the other two TextBoxes and fill them with the calculation which your now doing in textBox3_TextChanged . Now your result gets updated every time you change one of your TextBoxes.
Afterwards you can delete the textBox3_TextChanged .
As Dave also mentioned you could use other events than TextChanged like LostFocus or so. This would affect that your reslut isn't updated until you leave your Textbox and not every time you changed the contained text.
I advise you to experiment a bit with the differnt events. A good way to practically see how the are working and when they are raised, is to add an event handler for the specific event and set a break point into it.
I think it's important to go through this by yourself to get a deeper understanding of what your are doing. In the long way it's much better than getting a piece of code posted and simply using it.
Good luck 
|
|
|
|