0

I have a strange problem where MonoTouch seems to be either not compiling methods or not able to find a compiled method it is instructed to call, and only on the device in the Release configuration - Debug builds are fine. I've tried reproducing it with a simpler code sample with no luck, so I doubt you will be able to see the behavior with the code below. But this is essentially what I'm doing:

using System;
using MonoTouch.UIKit;

public class MyClass
{
    private UINavigationController _navController;
    private UIViewControler _viewController;

    public UINavigationController NavController
    {
        get
        {
            if (_navController == null)
            {
                if (_viewController == null)
                {
                    _viewController = new UIViewController();
                }
                _navController = new UINavigationController(_viewController);
            }
            return _navController;
        }
    }
}

Then, in some other method...

public void SomeMethod()
{
    MyClass myClass = new MyClass();
    var navController = myClass.NavController; // <-- This is where it throws
}

The exception I get is the standard JIT compile message, saying that it attempted to JIT get_NavController(). I find this very strange, because there's no virtual generics, no LINQ, the linker is off, and nothing else that normally causes JITs seems to be involved. I've also verified that it will throw for other methods and properties defined on MyClass, but not the constructor or System.Object inherited methods. Reflection reveals that myClass.GetType().GetMembers() has a MemberInfo for everything I would expect. Yet, only for Release|iPhone, I can't access these methods or properties. The only logical conclusion I can come to is that the aot compilation step is missing them, and I don't know why that would happen at all, let alone only in the Release configuration.

My question is, what could be causing such a situation, and what is the next step to fixing it? I'm not even sure where to go from here on debugging this, or what to file a bug about, because I can't reproduce it out of the context of our (much) larger project.

Update: The exact exception text was requested.

System.ExecutionException: Attempting to JIT compile method
'MyNamespace.MyClass.get_NavController ()' while running with --aot-only
David Merriman
  • 6,056
  • 1
  • 18
  • 18
  • Can you explain what "NavController" is supposed to be? It is not a method (no parantheses) and neither is it a "getter" (not get or set). COuld that be the whole problem? – Krumelur Apr 16 '12 at 18:41
  • Yes, it's a property with a getter. I've updated the code to fix my omission. – David Merriman Apr 16 '12 at 18:52

2 Answers2

1

This doesn't look like something that can be solved here.

I suggest filing a bug, and attach the entire project if you're unable to make a smaller test case. You can file private bugs only Xamarin employees have access to if you don't want your project to be publicly visible.

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • I'm not authorized to attach our whole source, but I'll file the bug and attach the binaries. – David Merriman Apr 16 '12 at 17:17
  • 1
    We isolated the cause. There's a bug in MonoDevelop when referencing an assembly that is also an iOS app. It gives the compiler the path to the stripped assembly inside the app bundle instead of the normal compiled exe. Link: https://bugzilla.xamarin.com/show_bug.cgi?id=4530 – David Merriman Apr 20 '12 at 10:43
0

Could you try to explicitly declare the variable

UINavigationController navController = myClass.NavController;

Alternatively, I wonder if this is at all associated with needing to wait for the UIViewController.ViewDidLoad method to be called as the internals of the class may not yet have been initialized?

Just shots in the dark here, I can't think of a reason why your code wouldn't work.

AkiAki007
  • 429
  • 3
  • 16
  • In the actual code, the property is being passes as an argument to a function, but it will throw no matter how I use it. None of the code is concerned with views, just the controllers, and in the past it has worked; I'm still tracking down exactly when it broke. – David Merriman Apr 16 '12 at 17:32
  • To me that also indicates that there are cogs moving around and the code presented above might not be the actual guilty culprit and probably related to something else that is run-time. Are you at invoking that method using reflection? I honestly can't think of any other reason why the above code wouldn't work except that it isn't referenced explicitly anywhere and thus the iOS compiler is removing the code as it is not referenced to create an as small as possible executable. – AkiAki007 Apr 16 '12 at 22:20
  • As stated in the question, the property is not being called via reflection. – David Merriman Apr 17 '12 at 15:18