Solved

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

Posted on 2007-11-26
9
671 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
Comment Utility
try
lblPassPlan.text + "Gym && Swimming Pool"
0
 

Author Comment

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

Expert Comment

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

lblPassPlan.text = NewLabel
0
 

Author Comment

by:BlahMatt
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 48

Expert Comment

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

0
 

Author Comment

by:BlahMatt
Comment Utility
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
Comment Utility
and if you do the same with a textbox ?

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

Author Comment

by:BlahMatt
Comment Utility
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
Comment Utility
No problem
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Trouble with References... 5 21
.Net application crashing 6 19
Set form below another form 3 25
Create XML 5 30
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

772 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

11 Experts available now in Live!

Get 1:1 Help Now