Solved

.net Compact Framework: Assigning an & to a label throws out of memory exception

Posted on 2007-11-26
9
676 Views
Last Modified: 2013-12-05
I'm having a problem in my .net CF 2.0 application.

When I open a specific form I do a search (via web service) and find a client and all of their memberships. If I find a membership, I update the UI to display start date, pass description etc...

I was testing to make sure it works with all special characters (&^@#!/\^) etc and I've found that when I assign an ampersand (&) to any of the labels on the form, the memory usage just grows and grows until an outofmemory exception is thrown.

This does not happen on any other form (from what I can tell) and I can't reproduce it in a basic application with just one form.

Another thing to note is that this form is shown as a dialog.

The code I'm running:

lblPassPlan.text = "Plan: "
lblPassPlan.text = lblPassPlan.text & "Gym && Swimming Pool"   <-- I've tried this with one ampersand as well, same thing. It throws the outofmemory exception on this line.

Here is the message from the exception:

            StackTrace      "at System.PInvoke.EE.FastAllocateString()
at System.String.GetStringForStringBuilder()
at System.String.GetStringForStringBuilder()
at System.Text.StringBuilder.GetNewString()
at System.Text.StringBuilder.Append()
at System.String.ReplaceOrdinal()
at System.String.Replace()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.lblPassPlan_TextChanged()
at System.Windows.Forms.Control.OnTextChanged()
at System.Windows.Forms.Control.set_Text()
at ClassWireless.formValidation.UpdateUI()
at ClassWireless.formValidation.GetClientPass()
at ClassWireless.formValidation.btnSearch_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterModalDialog()
at System.Windows.Forms.Form.ShowDialog()
at ClassWireless.formMain.picMemberships_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Control.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at ClassWireless.formMain.Main()
"      String


0
Comment
Question by:BlahMatt
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 20352274
try
lblPassPlan.text + "Gym && Swimming Pool"
0
 

Author Comment

by:BlahMatt
ID: 20352303
Using + instead of & for the concatenation  throws the same exception.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 20352367
Dim NewLabel as string = lblPassPlan.text + "Gym && Swimming Pool"

lblPassPlan.text = NewLabel
0
 

Author Comment

by:BlahMatt
ID: 20352432
OK... it doesn't throw an oom exception when I assign the string to a variable first

However it takes an abnormally long amount of time on that line of code (Assigning to the label) and then the labels text property is "" so the label doesn't appear.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 48

Expert Comment

by:Mikal613
ID: 20352457
Dim NewLabel as string = lblPassPlan.text & "Gym && Swimming Pool"
lblPassPlan.Text = ""
lblPassPlan.text = NewLabel

0
 

Author Comment

by:BlahMatt
ID: 20352648
Assigning the labels text = "" didn't change anything from what I can tell.

Same behavior...

Dim sNewLabel As String = lblPassPlan.text & "Gym && Swimming Pool"
lblPassPlan.text = ""
lblPassPlan.text = sNewLabel (where sNewLabel = "Plan: Gym && Swimming Pool")

Here lblPassPlan.text is still ""
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 250 total points
ID: 20352685
and if you do the same with a textbox ?

Can you create a new label and see what happens?
0
 

Author Comment

by:BlahMatt
ID: 20353114
With a textbox it works and creating a new label worked.

I'm not certain what properties are different on that label that would cause that though. I can't find any.

I'm ok with just creating new labels though. Thanks Mikal!
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 20353128
No problem
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now