Windows Forms Throwing a system.OutOfMemoryException Additional information: Error creating window handle

I am having a problem that I haven't had before and I don't understand where it's comming from.

I have a child form called frmUse that has a button click event that calls objfrmPeople.show  This was working fine until just recently while I have been attempting to seperate the DB access into a seperate tier.  Now I am getting the error:

   An unhandled exception of type 'System.OutOfMemoryException' occurred in system.windows.forms.dll

   Additional information: Error creating window handle.

I am concerned that it may be somehow related to the Windows Forms Generated Code region since I was mucking around there while I was trying to set the form's databindings to a seperate tier. Below is the stack trace for the error.  I will be happy to post code but don't know what to post yet any direction will be appreciated.

I traped the error to get the stack trace:

   at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   at System.Windows.Forms.Control.CreateHandle()
   at System.Windows.Forms.Form.CreateHandle()
   at System.Windows.Forms.Control.get_Handle()
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.Control.Show()
   at Foundation.frmUse.btnPeople_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator.CHEYENNE\My Documents\Visual Studio Projects\Foundation\frmUse.vb:line 102
LVL 2
Bull_81073Asked:
Who is Participating?
 
DarthModCommented:
PAQed with points refunded (205)

DarthMod
Community Support Moderator
0
 
mydasxCommented:
show us the code please both your calling code and the behind the scenes code for the form.
0
 
anwar ul haqueCommented:
Hi
try to dispose the objects properly and increase your RAM if possible.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Bull_81073Author Commented:
---Code creating my form and com objects---

Module SubMain
    Public objfrmMain As frmMain
    Public objfrmUse As frmUse
    Public objfrmpeople As frmPeople
    Public objcomFound As comFound
    Public objfrmAddress As frmAddress
    Public objfrmNewAddress As frmNewAddress

    Public Sub Main()
        objcomFound = New comFound
        objcomFound.daState.Fill(objcomFound.DsFound1, "state")
        objcomFound.daAddress.Fill(objcomFound.DsFound1, "address")
        objcomFound.daPerson.Fill(objcomFound.DsFound1, "person")
        objcomFound.daSex.Fill(objcomFound.DsFound1, "sex")
        objfrmMain = New frmMain
        objfrmMain.ShowDialog()
    End Sub

----Button Click Event to Display The Form---
    Private Sub btnPeople_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPeople.Click
        objfrmpeople = New frmPeople
        objfrmpeople.MdiParent = objfrmMain
        objfrmpeople.StartPosition = FormStartPosition.CenterParent
        objfrmpeople.lblID.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Person_ID"))
        objfrmpeople.txtFName.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.First_Name"))
        objfrmpeople.txtLName.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Last_Name"))
        objfrmpeople.cmbSex.DataSource = objcomFound.DsFound1.Sex
        objfrmpeople.cmbSex.DisplayMember = "sexVal"
        objfrmpeople.cmbSex.ValueMember = "sexID"
        objfrmpeople.chkMail.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Current_Mail"))
        objfrmpeople.chkDead.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Deceased"))
        objfrmpeople.lblAdd.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Address.Address_ID"))
        objfrmpeople.chkMarried.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Married"))
        objfrmpeople.txtMaiden.DataBindings.Add(New System.Windows.Forms.Binding("Text", objcomFound.DsFound1, "Person.Maiden_Name"))
        objfrmpeople.chk100.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Donations_100"))
        objfrmpeople.chkPlaque.DataBindings.Add(New System.Windows.Forms.Binding("Checked", objcomFound.DsFound1, "Person.Plaque"))

        Try
            objfrmpeople.Show()  '<------- This is where the error is being thrown
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.Source & ControlChars.NewLine & ControlChars.NewLine & ex.Message & ControlChars.NewLine & ControlChars.NewLine & ex.StackTrace)
        End Try
    End Sub

----Below is the Form_Load Sub for the form I can't display----

    Private Sub frmPeople_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        bmFound = Me.BindingContext(objcomFound.DsFound1, "person")
        bmAddress = Me.BindingContext(objcomFound.DsFound1, "address")
        AddHandler bmFound.PositionChanged, AddressOf Position_Changed

        Position_Changed(sender, e)
        lockBoxes()

    End Sub


I will post the Windows Form Designer generated code in another post if you need to see it  (Its about 800 lines)
0
 
Bull_81073Author Commented:
I didn't think that I needed to dispose of the objects anymore, I was under the impression that .NET took care of that for you.

I am developing on a Zeon based machine with 1.5 GB RAM I don't think that's the problem.
0
 
anwar ul haqueCommented:
what i know about this exception...if your application is experiencing any unhandled exception while it is being desposed it will throw 'out of memory exception' that's why I told you to properly despose your objects as this has always been a good programming practice. always use try/catch block while you are accessing any external resource or file or database. and write the exception results into log file ..it will help you to trace the problem and secondly this will protect your application from being  crashed or halted...
0
 
anwar ul haqueCommented:
put these lines in try catch block and debug the application ...designer code itself can not throw out of memory exception...mind it :)

    objcomFound = New comFound
        objcomFound.daState.Fill(objcomFound.DsFound1, "state")
        objcomFound.daAddress.Fill(objcomFound.DsFound1, "address")
        objcomFound.daPerson.Fill(objcomFound.DsFound1, "person")
        objcomFound.daSex.Fill(objcomFound.DsFound1, "sex")
0
 
mydasxCommented:
is this the MDA error?
0
 
Bull_81073Author Commented:
Sorry I am not familiar with MDA
0
 
Bull_81073Author Commented:
I have tried the try catch with the dataAdapter fills but it still doesn't help
0
 
anwar ul haqueCommented:
Are you working with with .Net framework 1.1 ? If so try to install .net framework hotfix 1.1. tell me if you have already installed, otherwise you can run windows update and install hotfix.
You can download it from this location...
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=A8F5654F-088E-40B2-BBDB-A83353618B38
0
 
Bull_81073Author Commented:
I have the 2.0.50727 dotnetframework installed
0
 
anwar ul haqueCommented:
even then you need hotfix from microsoft..best luck :)
0
 
Bull_81073Author Commented:
I have solved the problem myself!

So you all know!

The problem was that I when I made the change to a seperated data tier (in objcomFound) I forgot to add the objcomfound. in front of the dataset name in the BindingManager Position_Changed sub.  Now I have forgotten to do thins in the past but it never gave me this error.  Strange to say the least.  I can only imagine that the error was exposing itself this way because of the way that the Position_Changed sub is called.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.