Solved

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

Posted on 2007-11-26
9
696 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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
 
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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

690 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