Switch to a different documentation area.

Xamarin - Documentation

iOS

change platform

  1. Xamarin
  2. iOS
  3. Troubleshooting

Troubleshooting

Table of contents
  1. 1. How do I create outlets or actions with Interface Builder?
  2. 2. System.Text.Encoding.GetEncoding throws NotSupportedException
  3. 3. System.MissingMethodException (anything else)
  4. 4. You are getting a ModelNotImplementedException
  5. 5. This class is not key value coding-compliant for the key XXXX
  6. 6. Unknown class XXXX in Interface Builder file
  7. 7. System.MissingMethodException: No constructor found for Foo.Bar::ctor(System.IntPtr)
  8. 8. Type {Foo} does not contain a definition for `GetNativeField' and no extension method `GetNativeField' of type {Foo} could be found
  9. 9. Warning for actions: The private method 'Foo' is never used. (CS0169)
  10. 10. mtouch failed with the following message: Cannot open assembly '/path/to/yourproject.exe'
  11. 11. Your sqlite3 version is old - please upgrade to at least v3.5.0!
  12. 12. Deploy to device fails with System.Exception: AMDeviceInstallApplication returned 3892346901
  13. 13. Code Completion is not working in MonoDevelop
  14. 14. MonoDevelop crashes when you copy text
  15. 15. MonoDevelop complains about Mono 2.4 required
  16. 16. Assertion at ../../../../mono/metadata/generic-sharing.c:704, condition `oti' not met
  17. 17. System.ExecutionEngineException: Attempting to JIT compile method (wrapper managed-to-managed) Foo[]:System.Collections.Generic.ICollection`1.get_Count ()
  18. 18. MonoDevelop source editor is extremely slow
  19. 19. Compiled application is very large
  20. 20. Installation Hangs
  21. 21. Ran out of trampolines of type 0
  22. 22. Ran out of trampolines of type 1
  23. 23. Ran out of trampolines of type 2
  24. 24. Debugger is unable to connect with the device
  25. 25. Error 134: mtouch failed with the following message:
  26. 26. Distribution identity is not shown in MonoDevelop project signing options
  27. 27. Error "AFCFileRefWrite returned: 1" during upload
  28. 28. Error "mtouch failed with no output"
  29. 29. Error "The binary you uploaded was invalid.  A pre-release beta version of the SDK was used to build the application"
  30. 30. Error "A pre-release beta version of the SDK was used to build the app"
  31. 31. Unhandled Exception: System.Exception: Failed to find selector someSelector: on {type}
  32. 32. MainWindow.xib.designer.cs file is not updated
  33. 33. UIAlertView or UIActionSheet vanish after being created
  34. 34. Project Always Runs in the iPad Simulator
  35. 35. ibtool returns error 133
  36. 36. "Can't create display binding for mime type: application/vnd.apple-<wbr/>interface-builder"
  37. 37. Startup crash when executing inside the iOS simulator
  38. 38. Simulator hangs during application installation

How do I create outlets or actions with Interface Builder?

Interface Builder changed between Xcode 3.1 (OS X 10.5) and Xcode 3.2 (OS X 10.6).  In Xcode 3.1, you would select your "App Delegate" in your Document window, then use the [+] button in the Class Outlet section of the Identity Inspector pane.

In Xcode 3.2, this changed. You now would select Tools → Library, select the Classes section, and select your class, e.g. AppDelegate.  There would then be an Outlets tab at the bottom of the Library dialog. See the MonoDevelop_HelloWorld sample.

System.Text.Encoding.GetEncoding throws NotSupportedException

You're maybe using an encoding that is not added by default. Check the Internationalization page to learn how to add support for more encoding.

System.MissingMethodException (anything else)

The member was likely removed by the linker, and thus doesn't exist in the assembly at runtime.  There are several solutions to this:

  • Add the [Preserve] attribute to the member.  This will prevent the linker from removing it.
  • When invoking mtouch, use the -nolink or -linksdkonly options.
    • -nolink disables all linking.
    • -linksdkonly will only link MonoTouch-provided assemblies, such as monotouch.dll.

Note that assemblies are linked so that the resulting executable is smaller; thus, disabling linking may result in a larger executable than is desirable.

You are getting a ModelNotImplementedException

If you are getting this exception this means that you are calling base.Method () on a class that overrides a Model. You do not need to call the base method in a class for models (these are classes that are flagged with the [Model] attribute).

This class is not key value coding-compliant for the key XXXX

If you get this error when loading a NIB file it means that the value XXXX was not found on your managed class. This means that you are missing a declaration like this:

[Connect]
TypeName XXXX { 
   get {
       return (TypeName) GetNativeField ("XXXX");
   }
   set {
       SetNativeField ("XXXX", value);
   }
}

The above definition is automatically generated by MonoDevelop for any XIB files that you add to MonoDevelop in the NAME_OF_YOUR_XIB_FILE.designer.xib.cs file.

Additionally, the types containing the above code must be a subclass of NSObject.  If the containing type is within a namespace, it should also have a [Register] attribute which provides a type name without a namespace (as Interface Builder doesn't support namespaces in types):

namespace MonoTouch.Samples.GLPaint {

    // The [Register] attribute overrides the type name registered
    // with the Objective-C runtime, in this case removing the namespace.
    [Register ("AppDelegate")]
    public class AppDelegate {/* ... */}
}

Unknown class XXXX in Interface Builder file

This error is generated if you define a class in your interface builder files but you do not provide the actual implementation for it in your C# code.

You need to add some code like this: 

public partial class MyImageView : UIView {
   public MyImageView (IntPtr handle) : base (handle {}
}

System.MissingMethodException: No constructor found for Foo.Bar::ctor(System.IntPtr)

This error is produced at runtime when the code tries to instantiate an instance of the classes that you referenced from your Interface Builder file.   This means that you forgot to add a constructor that takes a single IntPtr as a parameter.

The constructor with an IntPtr handle is used to bind managed objects with their unmanaged representations.   To fix this, add the following line of code to the class Foo.Bar:

public Bar (IntPtr handle) : base (handle) { }

Type {Foo} does not contain a definition for `GetNativeField' and no extension method `GetNativeField' of type {Foo} could be found

If you get this error in the designer generated files (*.xib.designer.cs), it means one of two things:

1) Missing partial class or base class

The designer-generated partial classes must have corresponding partial classes in user code that inherit from some subclass of NSObject, often UIViewController. Ensure that you have such a class for the type that is giving the error.

2) Default namespaces changed

The designer files are generated using your project's default namespace settings. If you have changed these settings, or renamed the project, the generated partial classes may no longer be in the same namespace as their user-code counterparts.

Namespace settings can be found in the Project Options dialog. The default namespace is found in the General->Main Settings section. If it is blank, the name of your project is used as the default. More advanced namespace settings can be found in the Source Code->.NET Naming Policies section.

Warning for actions: The private method 'Foo' is never used. (CS0169)

Actions for interface builder files are connected to the widgets by reflection at runtime, so this warning is expected.

You can use "#pragma warning disable 0169" "#pragma warning enable 0169" around your actions if you want to suppress this warning just for these methods, or add 0169 to the "Ignore warnings" field in compiler options if you want to disable it for your whole project (not recommended).

mtouch failed with the following message: Cannot open assembly '/path/to/yourproject.exe'

If you see this error message, generally the problem is the absolute path to your project contains a space.  This will be fixed in a future version of MonoTouch, but you can work around the issue by moving the project to a folder without spaces.

Your sqlite3 version is old - please upgrade to at least v3.5.0!

This happens when you do all of the following:

  1. Use Mono.Data.Sqlite
  2. Use Mac OS X Leopard (10.5)
  3. Run your app within the simulator.

The problem is that Mono is picking up the OS X libsqlite3.dylib, not the iPhoneSimulator's libsqlite3.dylib file.  Your app will work on the device, but just not your simulator.

The short term fix is to use Mac OS X Snow Leopard (10.6).  A fix for Leopard (10.5) will be released with a future MonoTouch version.

Deploy to device fails with System.Exception: AMDeviceInstallApplication returned 3892346901

This error means that the code-signing configuration for your certificate/bundle id does not match the provisioning profile installed on your device.  Confirm you have the appropriate certificate selected in Project Options->iPhone Bundle Signing, and the correct bundle id specified in Project Options->iPhone Application

Code Completion is not working in MonoDevelop

Ensure that you are using the latest MonoTouch version of MonoDevelop from http://monodevelop.com/Download/Mac_MonoTouch

If the issue is still present, please file a bug, attaching the "~/.config/MonoDevelop/log" log file.

If all else fails, you can try removing the code completion cache so that it is regenerated:

rm -r ~/.config/MonoDevelop/CodeCompletionData

Be careful that you type this command correctly or you could accidentally remove important files.

MonoDevelop crashes when you copy text

The popular Mac utilities QuickSilver, Google Toolbar and LaunchBar have clipboard features that corrupt MonoDevelop's memory. In their options, you can list MonoDevelop as a process they should not interfere with.

MonoDevelop complains about Mono 2.4 required

If you updated MonoDevelop due to a recent update, and when you try to start it again it complains about Mono 2.4 not being present, all you have to do is upgrade your Mono 2.4 installation.  

Mono 2.4.2.3_6 fixes some important problems that prevented MonoDevelop from running reliably, sometimes hung MonoDevelop at startup or prevented the code completion database from being generated.

Once you install the new Mono, MonoDevelop will start as expected.

Assertion at ../../../../mono/metadata/generic-sharing.c:704, condition `oti' not met

If you are receiving the following stack trace:

 * Assertion at ../../../../mono/metadata/generic-sharing.c:704, condition `oti' not met
Stacktrace:
    at System.Collections.Generic.List`1<object>..cctor () <0xffffffff>
    at System.Collections.Generic.List`1<object>..cctor () <0x0001c>
    at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>

It means that you are linking a static library compiled with thumb code into your project.  As of iPhone SDK release 3.1 (or higher at the time of this writing) Apple introduced a bug in their linker when linking non-Thumb code (MonoTouch) with Thumb code (your static library).  You will need to link with a non-Thumb version of your static library to mitigate this issue.

 

System.ExecutionEngineException: Attempting to JIT compile method (wrapper managed-to-managed) Foo[]:System.Collections.Generic.ICollection`1.get_Count ()

The [] suffix indicates that you or the class library are calling a method on an array through a generic collection, such as IEnumerable<>, ICollection<> or IList<>. As a workaround, you can explicitely force the AOT compiler to include such method by calling the method yourself, and by making sure that this code is executed before the call that triggered the exception. In this case, you could write:

Foo [] array = null;
int count = ((ICollection<Foo>) array).Count;

Which will force the AOT compiler to include the get_Count method.

MonoDevelop source editor is extremely slow

Sometimes the MonoDevelop source editor becomes extremely slow, appearing to hang for several seconds between typing characters.

This issue is very rare and extremely hard to reproduce - it usually cannot be reproduced on the same machine after restarting MonoDevelop. For this reason we would appreciate it if you could perform several debugging steps before restarting MonoDevelop, and send the results to us.

  1. Try closing the editor tab, and re-opening it. Does it take a little bit of editing or moving the caret around until the slowdown happens again?
  2. Disable "Beam Sync" using the "Quartz Debug" developer tool (which you can find using Spotlight), and check whether the source editor performance is restored to normal.
  3. Try repeating step (1) with Beam Sync still disabled.
  4. If the editor hangs for more than a few seconds, try to run "killall -QUIT monodevelop" in a terminal while it is hung. It may be difficult to time the kill command to happen while the editor is hung, but it's essential to do so, because the command forces Mono to write stack traces of all threads to the MD log, which we can use to discover what state the threads are in while the MD is hung.

Please attach the MD log, ~/.config/MonoDevelop/log (in future versions of MD it is ~/Library/Logs/MonoDevelop/MonoDevelop.log).

[NOTE: The above issue was fixed in MD 2.2 Final]

Compiled application is very large

In order to support debugging, debug builds contain additional code. Projects built in release mode are a fraction of the size.

As of MonoTouch 1.3 the debug builds included debugging support for every single component of Mono (every method in every class of the frameworks).  

With MonoTouch 1.4 we will introduce a finer grained method for debugging, the default will be to only provide debugging instrumentation for your code and your libraries, and not do this for all of the Mono assemblies (this will still be possible, but you will have to opt-in to debugging those assemblies).

Installation Hangs

Both Mono and MonoTouch installers hang if you have the iPhone Simulator running.   This problem is not limited to Mono or MonoTouch, this is a consistent problem across any software that tries to install software on MacOS Snow Leopard if the iPhone Simulator is running at installation time.

Make sure you quit the iPhone simulator and retry the installation.

Ran out of trampolines of type 0

If you get this message while running device,  You can create more type 0 trampolines (type SPECIFIC) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "ntrampolines=2048"

The default number of trampolines is 1024.  Try increasing this number until you have enough for your application.

Ran out of trampolines of type 1

If you make heavy use of recursive generics, you may get this message on device.  You can create more type 1 trampolines (type RGCTX) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "nrgctx-trampolines=2048"

The default number of trampolines is 1024.  Try increasing this number until you have enough for your usage of generics.

Ran out of trampolines of type 2

If you make heavy use interfaces, you may get this message on device.  You can create more type 2 trampolines (type IMT Thunks) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "nimt-trampolines=512"

The default number of IMT Thunk trampolines is 128.  Try increasing this number until you have enough for your usage of interfaces.

Debugger is unable to connect with the device

When you start debugging a device configuration, you will see the debugger show a dialog indicating that it is listening on a particular IP address. This IP address is also built into the application as a default setting. When you start the application in debug mode, it makes a connection to MonoDevelop, the debugger host. If it is unable to connect, the device will vibrate once.

There are several reasons the application may not be able to connect to the debugger:

If the device and the debugger host are on different networks, a firewall or private network may be preventing the application from connecting to the debugger host.

MonoDevelop may picked the wrong host IP address. MonoDevelop picks the first IP address on the machine, which, if you have multiple network interfaces, may not be the one you want. You can override the IP that MonoDevelop uses by quitting MonoDevelop and editing its settings file. This is in a hidden directory in in your home directory, ~/.config/MonoDevelop/MonoDevelopProperties.xml.

Look for the key "MonoTouch.Debugger.HostIP", and edit the value. If it is not present you will need to add it:

<Property key="MonoTouch.Debugger.HostIP" value="w.x.y.z"/>

where w.x.y.z is the IP you wish to use.

The debugger host's IP address may have changed. MonoDevelop has to embed the host's IP address in the application's default settings so that it knows what address to connect to. If the host's IP changes after you build the app, you need to rebuild and re-upload the app, or change the IP address entry in the app's Debug Settings

page on the device (open the Settings app on the device).

Error 134: mtouch failed with the following message:

This error could be raised if you are trying to build with -nolink on the MonoTouch 1.4 style of releases.  You can work around this error by specifying Extra Arguments in your monodevelop project configuration.  Add the argument

-nosymbolstrip

and the problem should be resolved.

Distribution identity is not shown in MonoDevelop project signing options

MonoDevelop 2.2 has a bug that causes it not to detect distribution certificates that contain a comma. Please update to MonoDevelop 2.2.1.

Error "AFCFileRefWrite returned: 1" during upload

While uploading an app to your device you may receive an Error "AFCFileRefWrite returned: 1". This can happen if you have a zero-length file.

Error "mtouch failed with no output"

The current release of MonoTouch and MonoDevelop fail when the project name or the directory where the solution or project are stored contain spaces.  To fix this:

  • Make sure that neither your project or the directory where it is stored contains a space.
  • In your project "Main Settings" make sure that the Project Name does not contain any spaces.

Error "The binary you uploaded was invalid.  A pre-release beta version of the SDK was used to build the application"

This error is usually caused with a project that was started in iPad development before MonoTouch 2.0.0 was released, you likely have some keys in your Info.plist like:

       <key>UIDeviceFamily</key>
       <array>
               <string>1</string>
       </array>

This keypair should be removed as MonoDevelop handles it for you automatically.

Error "A pre-release beta version of the SDK was used to build the app"

(Contributed by Ed Anuff)

Follow these steps:

  • Change the SDK version in iPhone Build to 3.2 or iTunes connect will reject it on upload because it is seeing an iPad compatible app built using an SDK version less than 3.2
  • Create a custom Info.plist for the project and explicitly set MinimumOSVersion to 3.0 in it.   This will override the MinimumOSVersion 3.2 value set by MonoTouch.   If you do not do this, the app will not be able to run on an iPhone.
  • Rebuild, zip and upload to iTunes connect.

Unhandled Exception: System.Exception: Failed to find selector someSelector: on {type}

This exception is caused by one of three things:

  1. You have provided a Selector to the Objective-C runtime without applying the corresponding [Export] attribute to a method
  2. You have enabled full linking and not applied the [Preverse] attribute to the [Export]ed method.
  3. You have applied the [Export] attribute to a private method in an inherited type.

MainWindow.xib.designer.cs file is not updated

There was a bug in MonoDevelop 2.4 that caused it not to group the MainWindow.xib file with the MainWindow.xib.designer file in new projects. This meant it would not update the designer code for that particular file.

This issue is fixed in the version of MonoDevelop that's available in its built-in updater, so please ensure you use the newer version.

You can fix existing projects by removing (not deleting) the xib and its designer file, then adding it back. This should re-group the files correctly.

UIAlertView or UIActionSheet vanish after being created

If you have some code like this:

var actionSheet = new UIActionSheet ("My ActionSheet", null, null, "OK", null){     
   Style = UIActionSheetStyle.Default 
}; 
actionSheet.Clicked += delegate (sender, args){ 
    Console.WriteLine ("Clicked on item {0}", args.ButtonIndex); 
};

the "actionSheet" object lives as a temporary variable in the function and as soon as the function terminates, the object is eligible for garbage collection, so it ends up being garbage collected.

To fix this problem, you need to keep a reference to "actionSheet" outside your method, somewhere that will live beyond your method.

Project Always Runs in the iPad Simulator

The iPhone SDK 4.0 installer installs 2 SDKs - the 3.2 SDK, for building iPad-only apps, and the 4.0 SDK, used for bulding iPhone and Universal apps. It also installs a 3.2 simulator, which simulates only an iPad, and a 4.0 simulator that simulates iPhone or iPhone 4. All older SDKs and simulators are removed.

MonoDevelop iPhone project build options include a setting for the SDK version that will be used in building your app. This setting can be found in Project Options->Build->iPhone Build.

New projects in MonoDevelop use the oldest installed SDK as their default SDK setting, and if the SDK specified does not exist, MonoDevelop will use the closest it can find to build your app. This was done so that  projects would not always requre the newest SDK. However, this currently results in the 3.2 SDK being used - which results in the iPad simulator being used.

To fix this by using the 4.0 SDK, go to Project Options->Build->iPhone Build and change the SDK value to "4.0" using the dropdown box. You must do this for each configuration and platform combination, accessed using the dropdowns at the top of the panel.

The SDK version should not be confused with the "Minimum OS version" setting. This value does not have to match the SDK version value - it affects the minimum version of the OS your app will install on, which can be older than the SDK, as long as you use only APIs that exist in the older OS, or guard use of newer features using runtime OS version checks. You should set it to the oldest OS version on which you test your app.

Note also that the Project->iPhone Simulator Target menu can be used to pick the simulator that is used by default when running/debugging a project. Additionally, the Run->Run With menu can be used to pick a specific simulator with which to run

ibtool returns error 133

This means that you have XCode 4 installed.   In XCode 4, the tool ibtool was removed, it is no longer possible to edit your XIB files with a standalone tool.

If you want to use Interface Builder, install XCode series 3, available from Apple's web site.

"Can't create display binding for mime type: application/vnd.apple-<wbr/>interface-builder"

This error happens if you try to create an iPhone UI from a non-iPhone project. Make sure that you start with an iPhone/iPad solution, it is not possible to just add iPhone UI elements to a non-iPhone/iPad project.

Startup crash when executing inside the iOS simulator

If you get a runtime crash (SIGSEGV) inside the simulator along with a stack trace that looks like this:

  at (wrapper managed-to-native) System.Reflection.Assembly.GetTypes (System.Reflection.Assembly,bool)
  at MonoTouch.ObjCRuntime.Runtime.RegisterAssembly (System.Reflection.Assembly) 
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr)
then you probably have one (or more) stale assembly in your simulator application directory. Such assemblies may exists since Apple iOS simulator adds and updates files but never deletes them. If this happens then the easiest solution is to select "Reset and Content and Settings..." from the simulator menu.
 
Warning: this will remove all files, applications and data from the simulator.
 
Next time you execute your application, MonoDevelop will deploy it into the simulator and there will be no old, stale assembly to cause the crash.
 

Simulator hangs during application installation

This can happen when application names include a '.' (dot) in their name. This is forbidden as the executable name in CFBundleExecutable - even if it can works in many other cases (like devices).

"The value should not include any extension on the name."
http://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/InfoPlistKeyReference.pdf