In this article

Tips for Updating Code to the Unified API

In this article

When updating older Xamarin solutions to the Unified API, the following errors might be encountered.

NSInvalidArgumentException Could Not Find storyboard Error

There is a bug in the current version of Visual Studio for Mac that can occur after using the automated migration tool to convert your project to the Unified APIs. After the update, if you get an error message in the form:

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: Could not find a storyboard named 'xxx' in bundle NSBundle...

You can do the following to solve this issue, locate the following build target file:

The Unified API does not provide an implicit conversion between NSDate
and .NET DateTime because it's not a lossless conversion. To prevent
errors related to DateTimeKind.Unspecified convert the .NET DateTime
to local or UTC before casting to NSDate.

Objective-C category methods are now generated as extension
methods in the Unified API. For example, code that previously
used UIView.DrawString would now reference
NSString.DrawString in the Unified API.

Code using AVFoundation classes with VideoSettings should change
to use the WeakVideoSettings property. This requires a Dictionary,
which is available as a property on the settings classes, for example:

Note: the MonoTouch.Dialog namespace remains the same
after migration. If your code uses MonoTouch.Dialog
you should continue to use that namespace - do not
change MonoTouch.Dialog to Dialog!

Common Compiler Errors

Other examples of common errors are listed below, along with the solution:

Error CS0012: The type 'MonoTouch.UIKit.UIView' is defined in an assembly that is not referenced.

Fix: This usually means the project references a component or NuGet package that has not been built with the Unified API. You should delete and re-add all Components and NuGet packages. If this does not fix the error, the external library may not yet support the Unified API.

Error MT0034: Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 'Xamarin.iOS.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 'Xamarin.Mobile, Version=0.6.3.0, Culture=neutral, PublicKeyToken=null'.

Fix: Delete the component that is causing this error and re-add to the project.

Error CS0234: The type or namespace name 'Foundation' does not exist in the namespace 'MonoTouch'. Are you missing an assembly reference?

Fix: The automated migration tool in Visual Studio for Mac should update all MonoTouch.Foundation references to Foundation, however in some instances these will need to be updated manually. Similar errors may appear for the other namespaces previously contained in MonoTouch, such as UIKit.

Fix: Change instances to RectangleF to CGRect, SizeF to CGSize, and PointF to CGPoint. The namespace using System.Drawing; should be replaced with using CoreGraphics; (if it isn't already present).

error CS1502: The best overloaded method match for 'CoreGraphics.CGContext.SetLineDash(System.nfloat, System.nfloat[])' has some invalid arguments

Fix: Change array type to nfloat[] and explicitly cast Math.PI.

grphc.SetLineDash (0, new nfloat[] { 0, 3 * (nfloat)Math.PI });

Error CS0115: `WordsTableSource.RowsInSection(UIKit.UITableView, int)' is marked as an override but no suitable method found to override

Fix: Change the return value and parameter types to nint. This commonly occurs in method overrides such as those on UITableViewSource, including RowsInSection, NumberOfSections, GetHeightForRow, TitleForHeader, GetViewForHeader, etc.