Bug 26058 - Stringbuilder.Append drops out of the code without an error
Summary: Stringbuilder.Append drops out of the code without an error
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.6.0
Hardware: All Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-01-15 06:03 UTC by Paul Johnson
Modified: 2016-05-26 21:17 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2015-01-15 06:03:24 UTC
Consider the following piece of code

private string DeviceId
                var sb = new StringBuilder();
                string[] allowed =
                        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
                        "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
                int next = 0;
                Random r = new Random();
                for (int n = 0; n < 15; ++n)
                    next = r.Next(36);

                return sb.ToString();

When the debugger is run through it, when the append is hit, the code stops and returns giving nothing. The problem is that this is not a consistent bug. For example, that may work, but using it to append something using 

sb.Append(string.Format(...)) will cause it to fall over (no exception given and the app continues as it always has)

So while the simple example above may work, the likes of 

private void GenerateLivestock()
            wvLCData.LoadHtmlString(string.Empty, null);
            var documents = NSBundle.MainBundle.BundlePath;
            var sb = new StringBuilder();
            sb.Append(File.ReadAllText(Path.Combine(documents, "HTML/top3.html")));
            sb.Append(@"<table width=100%>");
            var mobEvents = (from m in thePaddock.Mobs
                                      from e in m.Events
                                      select new {Events = e.type, Date = e.date,Data = e.data}).OrderBy(t => t.Date).ToList();
            foreach (var m in mobEvents)
                var ds = Serialiser.GetValueFromData(m.Data, "TotalHead");
                sb.Append(string.Format("<td>{0} {1} {2} - {3}</td>", m.Events, ds, StringUtils.GetString("PadList.Live.Head"), m.Date.Date));
            sb.Append(File.ReadAllText(Path.Combine(documents, "HTML/bottom.html")));
            wvLCData.LoadHtmlString(sb.ToString(), new NSUrl(""));

will stop at the second Append (a breakpoint at the var line is never reached)

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: f3d1a29c-1ba2-4a83-a193-1087efe91a85
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: dfb682f
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/PFJ/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.2
Darwin Pauls-iMac.local 14.1.0 Darwin Kernel Version 14.1.0
    Sun Dec 28 21:20:58 PST 2014
    root:xnu-2782.10.72~3/RELEASE_X86_64 x86_64
Comment 1 Abhishek 2015-01-15 09:21:20 UTC
Hi Paul, 

I have reviewed your problem and find that your code is working fine if debugger hits after launching the application successfully and we are able to debug and inspect value of string builder. In this case I have debug your code on button click event.

However, if debugger hits before launching the application and application does not launch successfully with in 10 seconds then your application will be killed. This is the feature of Xamarin iOS debugger.

You can refer this in below xamarin doc under section "Breakpoints":

Please let me know when you are try to hit breakpoint either "Before launching the application" or "After launching the application"?

Comment 2 Paul Johnson 2015-01-15 16:57:47 UTC
This happens well into the app and I'm well aware of the 12 second before things die rule ;)

The break point would be at the line 

sb.Append(@"<table width=100%>");

It is never reached and no exceptions raised by say having the file being read in not being available.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2015-01-16 03:29:56 UTC
This does not look like something we can easily reproduce (there's nothing in your code that suggest the behavior you're seeing).

Can you add Console.WriteLine statements to try to get the exact execution flow? That's usually the easiest way to track down these problems.
Comment 4 Sebastien Pouliot 2016-05-26 21:17:34 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!