Bug 14507 - Mysterious null reference exceptions
Summary: Mysterious null reference exceptions
Status: RESOLVED DUPLICATE of bug 14552
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.4.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-09-06 18:23 UTC by Michael Bayne
Modified: 2013-09-10 18:00 UTC (History)
2 users (show)

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

A project that demonstrates the failure (4.86 MB, application/x-bzip2)
2013-09-06 18:23 UTC, Michael Bayne
Full source file from which excerpts were taken (6.54 KB, application/octet-stream)
2013-09-06 18:25 UTC, Michael Bayne

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 Michael Bayne 2013-09-06 18:23:46 UTC
Created attachment 4798 [details]
A project that demonstrates the failure

Standard caveat: I am writing code in Java, transcoding it to CLR bytecode via IKVM, and then running that in MonoTouch. This has worked so far, so when I upgrade MonoTouch and things start breaking (in mysterious ways), I report bugs to you.

The following code (roughly, the full class is attached):

public class IOSFont extends AbstractFont {
  public static void registerVariant(String name, Style style, String variantName) {
    Map<String,String> styleVariants = _variants.get(style);
    if (styleVariants == null) {
      _variants.put(style, styleVariants = new HashMap<String,String>());
    styleVariants.put(name, variantName);
  private static Map<Style,Map<String,String>> _variants = new HashMap<Style,Map<String,String>>();
  static {
    registerVariant("American Typewriter", Style.BOLD, "American Typewriter Bold");

crashes with a null reference exception on the _variants.get() line. If I modify the code thusly:

  public static void registerVariant(String name, Style style, String variantName) {
    Object svs = _variants.get(style);
    if (svs == null) {
      _variants.put(style, new HashMap<String,String>());
    Map<String,String> styleVariants = _variants.get(style);
    styleVariants.put(name, variantName);

it does not crash.

I am unfortunately unable to inspect the CLR bytecode generated by IKVM in this situation because monodis crashes trying to disassemble the generated DLL:

Missing method .ctor in assembly /Users/mdb/monotouch-null/bin/playn-tests-ios.dll, type System.ComponentModel.EditorBrowsableAttribute
* Assertion at class.c:5545, condition `!mono_loader_get_last_error ()' not met

but that's neither here nor there.

If I fix the above crash, I see mysterious null pointers elsewhere in my code where things used to work perfectly well and clearly nulls should not exist. So there's something going horribly wrong deep down under the covers. Hopefully this canary in the coal mine will provide some clue as to what is going wrong.

The attached project contains two sets of DLLs. Copy:

  bin/fails/playn-tests-ios.dll to bin/playn-tests-ios.dll

and build and run to see the failing behavior. Copy:

  bin/quote_works_quote/playn-tests-ios.dll to bin/playn-tests-ios.dll

to see the workaround I described above.

Let me know if any other information would be useful in debugging the issue. I can try to isolate the issue further if that is necessary to make further progress.

Comment 1 Michael Bayne 2013-09-06 18:25:16 UTC
Created attachment 4799 [details]
Full source file from which excerpts were taken
Comment 2 Sebastien Pouliot 2013-09-08 12:22:38 UTC
> This has worked so far, so when I upgrade MonoTouch and things start breaking 

On which version did it work ?

and which version do you use now ?

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button). 

Also do you remember if the NRE occured:

* only occured on the simulator ?


* did the same happen on devices ?
Comment 3 Michael Bayne 2013-09-10 17:27:26 UTC
I've only seem this error in the simulator. I haven't actually tried it on a device, but I'll do so now.

The code used to work on, am now using:

=== Xamarin Studio ===

Version 4.0.12 (build 3)
Installation UUID: d4c13a1a-2b18-4bad-9ab0-6c04281aeac8
	Mono 3.2.0 ((no/7c7fcc7)
	GTK 2.24.20
	GTK# (
	Package version: 302000000

=== Apple Developer Tools ===

Xcode 4.6.3 (2068)
Build 4H1503

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.iOS ===

Version: (Indie Edition)
Hash: 62e07d5
Build date: 2013-26-08 14:21:47-0400

=== Xamarin.Android ===

Version: 4.8.1 (Starter Edition)
Android SDK: /Users/mdb/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		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)
Java SDK: /usr
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

=== Build Information ===

Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

=== Operating System ===

Mac OS X 10.8.4
Darwin usui.local 12.4.0 Darwin Kernel Version 12.4.0
    Wed May  1 17:57:12 PDT 2013
    root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

If it's helpful to compare, I can provide a build made with the old toolchain for comparison.
Comment 4 Michael Bayne 2013-09-10 17:41:26 UTC
Interesting development: I had been only using debug builds, but if I do a release build (on the simulator) there seem to be no mysterious null reference exceptions.

I'm still fiddling with getting a build on a device. The only device I have handy is running the iOS 7 dev build and I hadn't updated my Xcode toolchain to iOS 7, so I'm doing that now.
Comment 5 Sebastien Pouliot 2013-09-10 17:42:37 UTC
Fixed in 6.4.5 in beta (should be in stable any minute now).

*** This bug has been marked as a duplicate of bug 14552 ***
Comment 6 Michael Bayne 2013-09-10 18:00:18 UTC
Great, thanks!