Solved

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

Posted on 2007-11-26
9
686 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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). …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

756 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