I've got some code that's been working great, but I've noticed it crashes in release mode. After a few hours of debugging, I've nailed it down to an issue with a constant being null in release mode. The variable "IGLabelConstants.IGTextStyleFontAttributeName" is null in release mode, but not in debug mode.
Here is the relative code (the length of text is forced to 4 characters above and is not part of the issue):
if (IGLabelConstants.IGTextStyleFontAttributeName == null) Console.WriteLine("ERMAGOOADODF!"); NSMutableDictionary attributes1 = new NSMutableDictionary();attributes1.Add(IGLabelConstants.IGTextStyleFontAttributeName, Constants.FONT_BigWeightDisplay_Whole);_mainWeightDisplay.AddAttributes(attributes1, new NSRange(0, _mainWeightDisplay.Text.Length - 2)); NSMutableDictionary attributes2 = new NSMutableDictionary();attributes2.Add( IGLabelConstants.IGTextStyleFontAttributeName, Constants.FONT_BigWeightDisplay_Decimal);_mainWeightDisplay.AddAttributes(attributes2, new NSRange(_mainWeightDisplay.Text.Length - 1, 1)); // we make the decimal a different font to get a round decimal pointNSMutableDictionary attributes3 = new NSMutableDictionary();attributes3.Add(IGLabelConstants.IGTextStyleFontAttributeName, Constants.FONT_BigWeightDisplay_Period);_mainWeightDisplay.AddAttributes(attributes3, new NSRange(_mainWeightDisplay.Text.Length - 2, 1));
In the console in release mode you see the "ERMAGOOADODF!" string, however it is not null and does not throw an exception when in debug mode.
I've tried to just pass in a hardcoded string of the same value, but that has not worked as an alternative:
attributes3.Add(NSObject.FromObject("IGTEXTFONT"), Constants.FONT_BigWeightDisplay_Period);
It looks like it only happens in release mode on a device, the emulator works fine. Please let me know if you have any suggestions, I may have to find another route for now.
Very happy to say after another hour I figured it out! The MonoTouch compiler is stripping this field when compiling for release, so I had to add the following to the additional mtouch compiler parameters:
--nosymbolstrip=IGTextStyleFontAttributeName
I figured that out from reading a similar issue here:http://stackoverflow.com/questions/15150412/monotouch-binding-to-nsstring-field-returning-null-in-release-builds
Hope that helps someone else!
Hi Roger,
Thanks for providing the informational link for others to view should they encounter this issue and need a solution.
I did test out the scenario you mentioned in your first post to see if the issue occurs for me, but the value didn't get stripped out when I changed to release. Yesterday, I did update my Xamarin software, so this issue could be resolved in newer version of their product. If you click on the Xamarin Studio (menu) > About Xamarin Studio, and then click on Show Details. What version do you have for Xamarin Studio, Mono and Xamarin.iOS? Also, did this issue occur when testing on a device or simulator? My test project used the simulator.
Torrey,
The issue only occurred on a physical device and when in release mode - it worked fine in an emulator in release mode.
I am running the latest version of Xamarin.iOS in the Alpha channel, here is that info:
Xamarin StudioVersion 4.1.7 (build 87)Runtime: Mono 3.2.0 ((no/7c7fcc7) GTK 2.24.20 GTK# (2.12.0.0) Package version: 302000000
Apple Developer ToolsXcode 4.6.2 (2067.2)Build 4H1003
Xamarin.iOSVersion: 6.4.0.2 (Business Edition)Hash: c9f7659Branch: Build date: 2013-18-07 21:36:03-0400