2

A stack overflow is occurring in the auto-generated code for my winform. It happens only at the start of the auto-generated code for the form, not any of the controls in it. I tried removing the first line, and it happened on the next one. There is no stack trace or inner exception, please help.

EDIT

Here is my code for the form:

namespace Eternal_Continent
{
    public partial class Almanac : Form
    {
        public Almanac()
        {
            InitializeComponent();
        }
        public List<string> Content = new List<string>();
        private void Almanac_Load(object sender, EventArgs e)
        {
            timer1.Interval = 5000;
            PrivateFontCollection pfc = new PrivateFontCollection();
            pfc.AddFontFile(Application.StartupPath + "\\Resources\\font_name.ttf");
            textBox1.Font = new Font(pfc.Families[0], 36);
        }

        private void Almanac_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            Hide();
        }
    }
}

And here is the designer's:

namespace Eternal_Continent
{
    partial class Almanac
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Almanac));
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.BackColor = System.Drawing.Color.Khaki;
            this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBox1.Location = new System.Drawing.Point(0, 0);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.ReadOnly = true;
            this.textBox1.Size = new System.Drawing.Size(546, 582);
            this.textBox1.TabIndex = 0;
            // 
            // timer1
            // 
            this.timer1.Enabled = true;
            // 
            // Almanac
            // I removed the autoscale lines here, because I wanted to see if it would still create errors, it did
            this.BackgroundImage = Properties.Resources.Stone;
            this.ClientSize = new System.Drawing.Size(546, 582);
            this.Controls.Add(this.textBox1);
            this.Icon = Properties.Textures.EternalContinent1;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Almanac";
            this.Text = "Almanac";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Almanac_FormClosing);
            this.Load += new System.EventHandler(this.Almanac_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
            this.Dispose();
        }

        #endregion
        private System.Windows.Forms.Timer timer1;
        public System.Windows.Forms.TextBox textBox1;
    }
}

EDIT #2 Removing the Dispose() line causes

The current process has used all of its system allowance of handles for Window Manager objects

in my Resources.Designer.cs.

10
  • 1
    Did you alter/edit the designer code? Commented Jan 3, 2016 at 0:55
  • without some code to reference, the best I can throw at you is this: did you create an endless loop somewhere? Commented Jan 3, 2016 at 0:56
  • Plutonix, I did because I wanted to see if it would continually throw the error, but other than that, no. I removed one line, to see if it would keep occuring. Paul, as far as I know, there are no loops anywhere, It's auto generated code by VS. Commented Jan 3, 2016 at 0:57
  • What Paul meant was: did you create any endless recursion (method that calls itself)? Please show the code, your own and the designer's, so we can get an idea of what happened. Commented Jan 3, 2016 at 1:02
  • I uploaded the code now. Commented Jan 3, 2016 at 1:07

2 Answers 2

0

I tried your code and I got an ObjectDisposed exception. On debugging it turns out that your Auto-generated code has the last line as this.Dispose(), which is incorrect.

Once I deleted that line (last line of InitializeComponent() ) the designer and the code worked fine without any errors

Note that I had to comment out the below lines related to the resources since I do not have that in my project & file-system

// Almanac.cs
pfc.AddFontFile(Application.StartupPath + "\\Resources\\font_name.ttf");

// Almanac.Designer.cs
this.BackgroundImage = Properties.Resources.Stone;
this.Icon = Properties.Textures.EternalContinent1;

You should also comment out these lines from your code to make sure you get the same results as I get, and then include them one at a time to make sure they are not causing any issues

NOTE: I am using VS 2013 on Win 7

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this fixed it. It's good that this error has been resolved.
0

Often this will be down to accidental, indirect recursion. I have an old answer here that might help: https://stackoverflow.com/a/4734422/26414

It's also worth noting that if you step through using F11 you might see the looping pattern that tells you what's what. Be aware of which thread you're debugging, too. I believe you get a darker yellow highlight for the current line when stepping-through, if there are multiple threads with user code executing.

1 Comment

This didn't help me, I'm not seeing any recursion :\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.