Xamarin 的故障排除提示Troubleshooting Tips for Xamarin.iOS

Xamarin 无法解析 ValueTupleXamarin.iOS cannot resolve System.ValueTuple

发生此错误的原因是与 Visual Studio 不兼容。This error occurs due to an incompatibility with Visual Studio.

  • Visual Studio 2017 Update 1 (版本15.1 或更低版本)仅与ValueTuple NuGet 4.3.0 (或更早版本)兼容。Visual Studio 2017 Update 1 (version 15.1 or older) is only compatible with System.ValueTuple NuGet 4.3.0 (or older).

  • Visual Studio 2017 Update 2 (版本15.2 或更高版本)仅与ValueTuple NuGet 4.3.1或更高版本兼容。Visual Studio 2017 Update 2 (version 15.2 or newer) is only compatible with the System.ValueTuple NuGet 4.3.1 or newer .

请选择与你的 Visual Studio 2017 安装相对应的正确 ValueTuple NuGet。Please choose the correct System.ValueTuple NuGet that corresponds with your Visual Studio 2017 installation.

正在接收 "检索更新信息时出错" 错误消息Receiving 'Error Retrieving Update Information' Error Message

尝试更新软件时,如果显示此错误消息,请尝试重新启动 IDE 并注销,然后重新登录到 IDE 中的帐户。When attempting to update the software and this error message appears, please try restarting your IDE and logging out and then back in to your account in the IDE.

如何实现通过 Interface Builder 创建插座或操作?How do I create outlets or actions with Interface Builder?

随着 Visual Studio for Mac 和 Visual Studio 中的 Xamarin Designer for iOS 的引入,Xamarin iOS 开发人员现在可以利用通过情节提要和 xib 创建 UI。With the Introduction of the Xamarin Designer for iOS in Visual Studio for Mac and Visual studio, Xamarin.iOS developers can now take advantage of creating a UI through Storyboards and .xibs. 有关使用设计器的详细信息,请参阅iOS指南。Refer to the Hello, iOS guides for more information on using the designer.

有关在 IB 中使用输出口和操作的详细信息,请参阅 Apple 的插座操作指南。You can also refer to Apple's Outlet and Actions guides for more information on using Outlets and Actions in IB.

Encoding.getencoding 抛出 NotSupportedExceptionSystem.Text.Encoding.GetEncoding throws NotSupportedException

你可能正在使用默认情况下未添加的编码。You may be using an encoding that is not added by default. 查看国际化页面,了解如何添加对更多编码的支持。Check the Internationalization page to learn how to add support for more encoding.

MissingMethodException (其他任何内容)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:

  • 向成员添加[Preserve]特性。Add the [Preserve] attribute to the member. 这会阻止链接器删除它。This will prevent the linker from removing it.
  • 调用mtouch时,请使用 -nolink-linksdkonly选项:When invoking mtouch, use the -nolink or -linksdkonly options:
    • -nolink禁用所有链接。-nolink disables all linking.
    • -linksdkonly将仅链接 xamarin 提供的程序集(如xamarin),同时保留用户创建的程序集中的所有类型(即应用项目)。-linksdkonly will only link Xamarin.iOS-provided assemblies, such as xamarin.ios.dll, while preserving all types in user-created assemblies (ie. your app projects).

请注意,对程序集进行了链接,使生成的可执行文件更小;因此,禁用链接可能导致比预期更大的可执行文件。Note that assemblies are linked so that the resulting executable is smaller; thus, disabling linking may result in a larger executable than is desirable.

正在获取 ModelNotImplementedExceptionYou are getting a ModelNotImplementedException

如果您收到此异常,则表示您正在调用 base。重写模型的类上的方法()。If you are getting this exception this means that you are calling base.Method () on a class that overrides a Model. 不需要在模型的类中调用基方法(这些类是用 [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).

此类不符合键 XXXX 的键值编码This class is not key value coding-compliant for the key XXXX

如果在加载笔尖文件时收到此错误,则表示在托管类上找不到值 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);
   }
}

对于添加到 NAME_OF_YOUR_XIB_FILE.designer.xib.cs 文件中 Visual Studio for Mac 的任何 XIB 文件,将自动 Visual Studio for Mac 生成上述定义。The above definition is automatically generated by Visual Studio for Mac for any XIB files that you add to Visual Studio for Mac in the NAME_OF_YOUR_XIB_FILE.designer.xib.cs file.

此外,包含上述代码的类型必须是NSObject的子类。Additionally, the types containing the above code must be a subclass of NSObject. 如果包含类型在命名空间中,则它还应具有一个[Register]特性,该特性提供不带命名空间的类型名称(因为 Interface Builder 不支持类型中的命名空间):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 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 {/* ... */}
}

Interface Builder 文件中的未知类 XXXXUnknown class XXXX in Interface Builder file

如果在接口生成器文件中定义类,但没有在C#代码中提供它的实际实现,则会生成此错误。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 {}
}

MissingMethodException:找不到 Foo:: ctor (system.string)的构造函数System.MissingMethodException: No constructor found for Foo.Bar::ctor(System.IntPtr)

当代码尝试实例化从 Interface Builder 文件中引用的类的实例时,将在运行时生成此错误。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. 这意味着你忘记添加使用单个 IntPtr 作为参数的构造函数。This means that you forgot to add a constructor that takes a single IntPtr as a parameter.

带有 IntPtr 句柄的构造函数用于绑定托管对象及其非托管表示形式。The constructor with an IntPtr handle is used to bind managed objects with their unmanaged representations.

若要解决此问题,请将以下代码行添加到类 Foo. Bar:To fix this, add the following line of code to the class Foo.Bar:

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

类型 {Foo} 不包含 GetNativeField 的定义,并且找不到类型为 {Foo} 的扩展方法 GetNativeFieldType {Foo} does not contain a definition for GetNativeField and no extension method GetNativeField of type {Foo} could be found

如果在设计器生成的文件(*. xib.designer.cs)中出现此错误,则表示以下两种情况之一:If you get this error in the designer generated files (*.xib.designer.cs), it means one of two things:

1)缺少分部类或基类1) Missing partial class or base class

设计器生成的分部类在用户代码中必须具有相应的分部类,这些类从 NSObject的某些子类继承,通常 UIViewControllerThe 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)更改了默认命名空间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. 可以在源代码-> .Net 命名策略"部分中找到更高级的命名空间设置。More advanced namespace settings can be found in the Source Code->.NET Naming Policies section.

操作警告:从未使用私有方法 "Foo"。Warning for actions: The private method 'Foo' is never used. CS0169(CS0169)

接口生成器文件的操作在运行时通过反射连接到小组件,因此应该出现此警告。Actions for interface builder files are connected to the widgets by reflection at runtime, so this warning is expected.

如果要针对这些方法仅禁止显示此警告,可以在操作中使用 "#pragma 警告禁用 0169" #pragma 警告启用 0169 "; 如果想要为整个项目禁用此警告,请将0169添加到" 编译器选项 "中的" 忽略警告 "字段(而不是建议使用)。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 失败,出现以下消息:无法打开程序集 "/path/to/yourproject.exe"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. 此问题将在未来的 Xamarin 版本中得到解决,但你可以通过将项目移到没有空格的文件夹来解决此问题。This will be fixed in a future version of Xamarin.iOS, but you can work around the issue by moving the project to a folder without spaces.

你的 sqlite3 版本已过时-请升级到至少 v 3.5.0!Your sqlite3 version is old - please upgrade to at least v3.5.0!

执行以下所有操作时,会发生这种情况:This happens when you do all of the following:

  1. 使用 MonoUse Mono.Data.Sqlite
  2. 使用 Mac OS X Leopard (10.5)Use Mac OS X Leopard (10.5)
  3. 在模拟器中运行应用。Run your app within the simulator.

问题在于单声道是指 OS X libsqlite3.dylib,而不是 iPhoneSimulator 的 libsqlite3.dylib 文件。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.

部署到设备失败,出现系统错误。异常: AMDeviceInstallApplication 返回3892346901Deploy to device fails with System.Exception: AMDeviceInstallApplication returned 3892346901

此错误表示证书/捆绑 id 的代码签名配置与设备上安装的预配配置文件不匹配。This error means that the code-signing configuration for your certificate/bundle id does not match the provisioning profile installed on your device. 确认在项目选项中选择了适当的证书-> iPhone 捆绑签名,以及在项目选项-> iPhone 应用程序中指定的正确的捆绑 idConfirm you have the appropriate certificate selected in Project Options->iPhone Bundle Signing, and the correct bundle id specified in Project Options->iPhone Application

代码完成在 Visual Studio for Mac 中不起作用Code Completion is not working in Visual Studio for Mac

确保使用最新版本的 Visual Studio for Mac 和 XamarinEnsure that you are using the latest version of Visual Studio for Mac and Xamarin.iOS

如果问题仍然存在,请提交bug,附加 ~/Library/Logs/XamarinStudio-{VERSION}/Ide-{TIMESTAMP}.logAndroidTools-{timestamp} .log,并附加组件-{TIMESTAMP} .log日志文件。If the issue is still present, please file a bug, attaching the ~/Library/Logs/XamarinStudio-{VERSION}/Ide-{TIMESTAMP}.log, AndroidTools-{TIMESTAMP}.log, and Components-{TIMESTAMP}.log log files.

如果所有其他操作都失败,可以尝试删除代码完成缓存,以便重新生成它:If all else fails, you can try removing the code completion cache so that it is regenerated:

[rm -r ~/.config/XamarinStudio-{VERSION}/CodeCompletionData]

请小心键入此命令,否则可能会意外地删除重要文件。Be careful that you type this command correctly or you could accidentally remove important files.

复制文本时出现 Visual Studio for Mac 崩溃Visual Studio for Mac crashes when you copy text

常用的 Mac 实用程序 QuickSilver、Google 工具栏和启动栏具有 Visual Studio for Mac 的内存损坏的剪贴板功能。The popular Mac utilities QuickSilver, Google Toolbar and LaunchBar have clipboard features that corrupt Visual Studio for Mac's memory. 在这些选项中,你可以将 Visual Studio for Mac 列出为不应干扰的进程。In their options, you can list Visual Studio for Mac as a process they should not interfere with.

Visual Studio for Mac 投诉原因有关 Mono 2.4 的要求Visual Studio for Mac complains about Mono 2.4 required

如果由于最近的更新而更新了 Visual Studio for Mac,并且当你尝试再次启动时,投诉原因不存在 Mono 2.4,你只需升级 mono 2.4 安装即可。If you updated Visual Studio for Mac 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 修复了一些 Visual Studio for Mac 无法可靠运行的重要问题,有时会在启动时挂起 Visual Studio for Mac 或阻止生成代码完成数据库。Mono 2.4.2.3_6 fixes some important problems that prevented Visual Studio for Mac from running reliably, sometimes hung Visual Studio for Mac at startup or prevented the code completion database from being generated.

安装新 Mono 后,Visual Studio for Mac 将按预期方式启动。Once you install the new Mono, Visual Studio for Mac will start as expected.

中的断言。/../../../mono/metadata/generic-sharing.c:704,不满足条件 "oti"Assertion at ../../../../mono/metadata/generic-sharing.c:704, condition `oti' not met

如果你正在接收以下 stack 跟踪: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>`

这意味着你要将使用 thumb 代码编译的静态库链接到你的项目中。It means that you are linking a static library compiled with thumb code into your project. 从 iPhone SDK 版本3.1 (在撰写本文时,或更高版本),Apple 在使用 Thumb 代码(静态库)链接非 Thumb 代码(Xamarin)时在其链接器中引入了 bug。你将需要与静态库的非 Thumb 版本链接,以减轻此问题。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 (Xamarin.iOS) with Thumb code (your static library).You will need to link with a non-Thumb version of your static library to mitigate this issue.

ExecutionEngineException:尝试 JIT 编译方法(托管到托管的包装) Foo []: ICollection'1. get_Count ()System.ExecutionEngineException: Attempting to JIT compile method (wrapper managed-to-managed) Foo[]:System.Collections.Generic.ICollection`1.get_Count ()

[] 后缀指示你或类库正在通过泛型集合(如 IEnumerable < >、ICollection < > 或 IList < > 调用数组中的方法。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<>. 作为一种解决方法,你可以通过自行调用方法,并确保在触发异常的调用之前执行此代码,从而显式强制 AOT 编译器包含此类方法。As a workaround, you can explicitly 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;

这将强制 AOT 编译器包含 get_Count 方法。Which will force the AOT compiler to include the get_Count method.

Visual Studio for Mac 源编辑器非常慢Visual Studio for Mac source editor is extremely slow

有时 Visual Studio for Mac 的源编辑器会变得非常慢,因此在键入字符之间等待几秒钟。Sometimes the Visual Studio for Mac source editor becomes extremely slow, appearing to hang for several seconds between typing characters.

此问题很少发生,并且很难重现-在 Visual Studio for Mac 重新启动之后,通常无法在同一台计算机上重现此问题。This issue is very rare and extremely hard to reproduce - it usually cannot be reproduced on the same machine after restarting Visual Studio for Mac. 出于此原因,如果你可以在重新启动 Visual Studio for Mac 之前执行几个调试步骤,则会非常感激,并将结果发送给我们。For this reason we would appreciate it if you could perform several debugging steps before restarting Visual Studio for Mac, 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. 使用 "Quartz 调试" 开发人员工具(你可以使用聚光灯查找)禁用 "横梁同步",并检查源编辑器性能是否还原为正常。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. 试用始终禁用了横梁同步的重复步骤(1)。Try repeating step (1) with Beam Sync still disabled.
  4. 如果编辑器挂起了几秒钟以上,请尝试在终端中运行 "killall-QUIT [Visual Studio for Mac]",同时将其挂起。If the editor hangs for more than a few seconds, try to run "killall -QUIT [Visual Studio for Mac]" in a terminal while it is hung. 当编辑器挂起时,可能很难终止 kill 命令,但执行此操作非常重要,因为该命令强制 Mono 将所有线程的堆栈跟踪写入 MD 日志,这样,我们可以使用它们来发现当 XS 挂起时线程处于哪些状态。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 XS is hung.

请附加 XS 日志, ~/Library/Logs/XamarinStudio-{VERSION}/Ide-{TIMESTAMP}.logANDROIDTOOLS-{timestamp} .Log,AND组件-{timestamp} .log (在旧版本的 XS/MonoDevelop 中,只需 send ~/Library/Logs/MonoDevelop-(3.0 | 2.8 | 2.6)/MonoDevelop.log)。Please attach the XS logs, ~/Library/Logs/XamarinStudio-{VERSION}/Ide-{TIMESTAMP}.log, AndroidTools-{TIMESTAMP}.log, and Components-{TIMESTAMP}.log (in older versions of XS/MonoDevelop, just send ~/Library/Logs/MonoDevelop-(3.0|2.8|2.6)/MonoDevelop.log).

备注

上述问题已在 XS 2.2 最终版本中修复 * *The above issue was fixed in XS 2.2 Final**

已编译的应用程序非常大Compiled application is very large

为了支持调试,调试版本包含其他代码。To support debugging, debug builds contain additional code. 在发布模式下生成的项目是大小的一小部分。Projects built in release mode are a fraction of the size.

自 Xamarin. iOS 1.3,调试版本包括针对 Mono 的每个组件(每类框架的每个方法)的调试支持。As of Xamarin.iOS 1.3 the debug builds included debugging support for every single component of Mono (every method in every class of the frameworks).

使用 Xamarin 1.4,我们将介绍一种更细化的调试方法,默认情况下,它只是为你的代码和库提供调试检测,而不是针对所有Mono 程序集执行此操作(这仍是可行的,但你需要选择对这些程序集进行调试。With Xamarin.iOS 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

如果你正在运行 iPhone 模拟器,则 Mono 和 Xamarin iOS 安装程序都挂起。Both Mono and Xamarin.iOS installers hang if you have the iPhone Simulator running. 此问题并不局限于 Mono 或 Xamarin,这是在安装时在 MacOS 雪 Leopard 上尝试安装软件的任何软件的一致性问题。This problem is not limited to Mono or Xamarin.iOS, 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.

请确保退出 iPhone 模拟器,然后重试安装。Make sure you quit the iPhone simulator and retry the installation.

已用完类型为0的 trampolinesRan out of trampolines of type 0

如果在运行设备时收到此消息,则可以通过修改项目选项 "iPhone Build" 部分来创建更多类型 0 trampolines (类型特定)。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"

Trampolines 的默认数目为1024。The default number of trampolines is 1024. 尝试增加此数量,直到你的应用程序已足够。Try increasing this number until you have enough for your application.

已用完类型为1的 trampolinesRan out of trampolines of type 1

如果大量使用递归泛型,则可能会在设备上收到此消息。If you make heavy use of recursive generics, you may get this message on device. 可以通过修改项目选项 "iPhone Build" 部分来创建更多类型 1 trampolines (类型 RGCTX)。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"

Trampolines 的默认数目为1024。The default number of trampolines is 1024. 请尝试增加此数量,直到你已有足够的使用泛型。Try increasing this number until you have enough for your usage of generics.

已用完类型为2的 trampolinesRan out of trampolines of type 2

如果使用接口,则可能会在设备上收到此消息。If you make heavy use interfaces, you may get this message on device. 可以通过修改项目选项 "iPhone Build" 部分来创建更多类型 2 trampolines (类型 IMT Thunk)。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"

IMT Thunk trampolines 的默认数目为128。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 trying to connect to the application. 调试器可能无法连接到应用程序的原因有多种,具体取决于连接的模式(USB 或 WiFi)。There are several reasons the debugger may not be able to connect to the application, depending on the mode you're using to connect (USB or WiFi).

如果设备和调试器主机位于不同网络上,则防火墙或专用网络可能会阻止应用程序在 WiFi 模式下连接到调试器主机。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 in WiFi mode.

Visual Studio for Mac 可能无法查询主机的正确 IPVisual Studio for Mac may not be able to query the correct IP of the host. 在 WiFi 模式下 Visual Studio for Mac 向应用程序提供它可以找到的主机的所有 Ip,应用程序会尝试所有这些 Ip 来确定是否可以使用这些 Ip 来连接到 Visual Studio for Mac。In WiFi mode Visual Studio for Mac gives the application all the IPs it can find of the host, and the application tries them all to see if it can use any of them to connect to Visual Studio for Mac.

另一台设备连接到主机上的 USB 端口。Another device is connected to a USB port on the host. 在少数情况下,连接到主机上的 USB 端口的其他设备被识别为在某种程度上干扰 USB 模式下的调试。In a few cases other devices connected to the USB ports on the host have been known to somehow interfere with debugging in USB mode.

如果 WiFi 或 USB 模式不起作用,则可以轻松尝试其他模式:在 Visual Studio for Mac 中,打开首选项,转到 "首选项"/"调试器/iPhone 调试器" 页,并切换 "通过 WiFi 而不是通过 USB 调试 iOS 设备" 复选框。If either WiFi or USB mode does not work, you can easily try the other: in Visual Studio for Mac, open the Preferences, go to the Preferences/Debugger/iPhone Debugger page, and toggle the "Debug iOS devices over WiFi instead of over USB" checkbox. 如果两者都不起作用,则可以在详细模式下查看有关设备控制台中故障的详细信息(通过将 "-v-v" 添加到项目选项中的其他 mtouch 参数启用)。If neither works, you can see more information about the failure in the device console in verbose mode (which is enabled by adding "-v -v -v" to the additional mtouch arguments in the project's options).

错误134: mtouch 失败,出现以下消息:Error 134: mtouch failed with the following message:

如果尝试在 Xamarin 1.4 版的版本上生成 nolink,则可能会引发此错误。This error could be raised if you are trying to build with -nolink on the Xamarin.iOS 1.4 style of releases. 可以通过在 monodevelop 项目配置中指定额外参数来解决此错误。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.

分发标识不显示在 Visual Studio for Mac 项目签名选项中Distribution identity is not shown in Visual Studio for Mac project signing options

Visual Studio for Mac 2.2 有一个 bug,该 bug 导致无法检测包含逗号的分发证书。Visual Studio for Mac 2.2 has a bug that causes it not to detect distribution certificates that contain a comma. 请更新到 Visual Studio for Mac 2.2.1。Please update to Visual Studio for Mac 2.2.1.

上传期间出现错误 "AFCFileRefWrite 返回: 1"Error "AFCFileRefWrite returned: 1" during upload

将应用上传到设备时,可能会收到错误 "AFCFileRefWrite 返回: 1"。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.

错误 "mtouch 失败,无输出"Error "mtouch failed with no output"

当存储解决方案或项目的项目名称或目录包含空格时,Xamarin 和 Visual Studio for Mac 的当前版本会失败。The current release of Xamarin.iOS and Visual Studio for Mac 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. SDK 的预发布 beta 版本用于生成应用程序 "A pre-release beta version of the SDK was used to build the application"

此错误通常是由于在2.0.0 发布之前在 iPad 开发中启动的项目引起的,你可能在信息中有一些密钥。 info.plist,如:This error is usually caused with a project that was started in iPad development before Xamarin.iOS 2.0.0 was released, you likely have some keys in your Info.plist like:

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

应删除此密钥,因为 Visual Studio for Mac 会自动对其进行处理。This keypair should be removed as Visual Studio for Mac handles it for you automatically.

错误 "用于构建应用的 SDK 的预发布 beta 版本Error "A pre-release beta version of the SDK was used to build the app"

(由 Ed Anuff 提供)(Contributed by Ed Anuff)

请执行这些步骤:Follow these steps:

  • 将 iPhone Build 中的 SDK 版本更改为3.2 或 iTunes connect 将在上传时拒绝它,因为它看到使用小于3.2 的 SDK 版本生成的 iPad 兼容的应用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
  • 为项目创建自定义 info.plist,并在其中将 MinimumOSVersion 显式设置为3.0。Create a custom Info.plist for the project and explicitly set MinimumOSVersion to 3.0 in it. 这将覆盖 Xamarin 设置的 MinimumOSVersion 3.2 值。This will override the MinimumOSVersion 3.2 value set by Xamarin.iOS. 如果未执行此操作,应用将无法在 iPhone 上运行。If you do not do this, the app will not be able to run on an iPhone.
  • 重新生成、压缩并上传到 iTunes connect。Rebuild, zip and upload to iTunes connect.

未处理的异常: someSelector:在 {type} 上找不到选择器Unhandled Exception: System.Exception: Failed to find selector someSelector: on {type}

此异常由以下三种情况之一引起:This exception is caused by one of three things:

  1. 你向目标 C 运行时提供了一个选择器,而未将相应的 [Export] 特性应用于方法You have provided a Selector to the Objective-C runtime without applying the corresponding [Export] attribute to a method
  2. 已启用完全链接,但未将 [Preserve] 属性应用于 [Export] ed 方法。You have enabled full linking and not applied the [Preserve] attribute to the [Export]ed method.
  3. 已将 [Export] 特性应用于继承类型中的私有方法。You have applied the [Export] attribute to a private method in an inherited type.

未更新 MainWindow.xib.designer.cs 文件MainWindow.xib.designer.cs file is not updated

Xamarin Studio 2.4 中存在 bug,导致它不会将 xib 文件与新项目中的 Mainwindow.xaml 文件组合在一起。There was a bug in Xamarin Studio 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.

此问题已在内置更新程序中提供的 Visual Studio for Mac 版本中得到解决,因此请确保使用较新版本。This issue is fixed in the version of Visual Studio for Mac that's available in its built-in updater, so please ensure you use the newer version.

可以通过删除(而不是删除) xib 及其设计器文件,然后再将其添加回去来修复现有项目。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 或 UIActionSheet 在创建后消失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);
};

"actionSheet" 对象作为函数中的临时变量存在,一旦函数终止,该对象就有资格进行垃圾回收,因此最终会进行垃圾回收。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.

若要解决此问题,需要保留对方法之外的 "actionSheet" 的引用,该引用将位于方法之外。To fix this problem, you need to keep a reference to "actionSheet" outside your method, somewhere that will live beyond your method.

项目始终在 iPad 模拟器中运行Project Always Runs in the iPad Simulator

IPhone SDK 4.0 安装程序安装了2个 Sdk-3.2 SDK,用于构建仅限 iPad 的应用和 4.0 SDK,用于生成 iPhone 和通用应用。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 building iPhone and Universal apps. 它还会安装一个3.2 模拟器,该模拟器仅模拟 iPad 和模拟 iPhone 或 iPhone 4 的4.0 模拟器。It also installs a 3.2 simulator, which simulates only an iPad, and a 4.0 simulator that simulates iPhone or iPhone 4. 删除所有旧版本的 Sdk 和模拟器。All older SDKs and simulators are removed.

Visual Studio for Mac iPhone 项目生成选项包含用于构建应用的 SDK 版本的设置。Visual Studio for Mac iPhone project build options include a setting for the SDK version that will be used in building your app. 此设置可在项目选项-> 生成 > IPhone 版本中找到。This setting can be found in Project Options->Build->iPhone Build.

Visual Studio for Mac 中的新项目使用最早安装的 SDK 作为其默认 SDK 设置,如果指定的 SDK 不存在,Visual Studio for Mac 将使用最接近的版本来构建你的应用。New projects in Visual Studio for Mac use the oldest installed SDK as their default SDK setting, and if the SDK specified does not exist, Visual Studio for Mac will use the closest it can find to build your app. 这样做是为了使项目不会始终需要最新的 SDK。This was done so that projects would not always require the newest SDK. 但是,这当前会导致使用 3.2 SDK,这会导致使用 iPad 模拟器。However, this currently results in the 3.2 SDK being used - which results in the iPad simulator being used.

若要使用 4.0 SDK 修复此问题,请转到项目选项-> 生成 > IPhone 版本> 并使用下拉框将 SDK 值更改为 "4.0"。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.

SDK 版本不应与 "最低操作系统版本" 设置混淆。The SDK version should not be confused with the "Minimum OS version" setting. 此值不必与 SDK 版本值匹配-它会影响你的应用程序将安装在其上的操作系统的最低版本(可以比 SDK 更早的版本),前提是你只使用了旧版本中的 Api,或者使用运行时操作系统版本签来保护新功能的使用。ks.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. 你应将其设置为在其上测试你的应用程序的最早的 OS 版本。You should set it to the oldest OS version on which you test your app.

另请注意,项目 > IPhone 模拟器目标> 菜单可用于选择运行/调试项目时默认使用的模拟器。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 返回错误133ibtool returns error 133

这意味着你已安装 XCode 4。This means that you have XCode 4 installed. 在 XCode 4 中,删除了工具 ibtool 后,就不能再使用独立工具编辑 XIB 文件。In XCode 4, the tool ibtool was removed, it is no longer possible to edit your XIB files with a standalone tool.

如果要使用 Interface Builder,请从 Apple 网站上安装XCode 系列 3If you want to use Interface Builder, install XCode series 3, available from Apple's web site.

"无法为 mime 类型创建显示绑定: application/vnd.apple.mpegurl. apple-interface-builder""Can't create display binding for mime type: application/vnd.apple-interface-builder"

如果尝试从非 iPhone 项目创建 iPhone UI,会发生此错误。This error happens if you try to create an iPhone UI from a non-iPhone project. 请确保你开始使用 iPhone/iPad 解决方案,但不能只是将 iPhone UI 元素添加到非 iPhone/iPad 项目。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.

在 iOS 模拟器内执行时启动崩溃Startup crash when executing inside the iOS simulator

如果在模拟器内获取运行时崩溃(SIGSEGV)以及如下所示的堆栈跟踪: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. 此类程序集可能存在,因为 Apple iOS 模拟器添加并更新文件,但不会删除它们。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.

警告

这会从模拟器中删除所有文件、应用程序和数据。This will remove all files, applications and data from the simulator. 下一次执行应用程序时,Visual Studio for Mac 会将其部署到模拟器,并且没有旧的过时程序集可导致崩溃。Next time you execute your application, Visual Studio for Mac 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. 这在 CFBundleExecutable 中被禁止作为可执行文件名称,即使它可以在许多其他情况(如设备)中运行。This is forbidden as the executable name in CFBundleExecutable - even if it can works in many other cases (like devices).

* "此值不应包含名称上的任何扩展名"。- https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/InfoPlistKeyReference.pdf*"The value should not include any extension on the name."- https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/InfoPlistKeyReference.pdf

错误:双击 xib 文件时,不支持 "自定义属性类型 0x43"Error: "Custom attribute type 0x43 is not supported" when double clicking .xib files

这是由于未正确设置环境变量时尝试打开 xib 文件引起的。This is caused by attempting to open .xib files when environment variables are set incorrectly. Visual Studio for Mac/Xamarin 的正常使用情况下不会发生这种情况,并且从/Applications 重新打开 Visual Studio for Mac 应能解决该问题。This should not happen with normal usage of Visual Studio for Mac/Xamarin.iOS, and re-opening Visual Studio for Mac from /Applications should fix the problem.

尝试更新软件时出现此错误消息,请发送电子邮件 *support@xamarin.com*When attempting to update the software and this error message appears, please e-mail *support@xamarin.com*

应用程序在模拟器上运行,但在设备上失败Application runs on simulator but fails on device

此问题可能以多种形式出现,并且不会始终产生一致的错误。This issue can manifest in several forms, and doesn't always produce a consistent error. 如果应用程序包含 xib,请检查以确保 xib 上的生成操作设置为InterfaceDefinitionIf the application contains a .xib, check to make sure the Build Action on the .xib is set to InterfaceDefinition. 这是 xib 的默认生成操作。This is the default build action for .xibs.

若要检查生成操作,请右键单击 "xib" 文件,然后选择 "生成操作"。To check the build action, right click on the .xib file and choose Build Action.

NotSupportedException:没有可用于编码437的数据System.NotSupportedException: No data is available for encoding 437

当在你的 Xamarin iOS 应用中包括第三方库时,尝试编译和运行该应用时,你可能会收到 "NotSupportedException:无数据可用于编码 437" 形式的错误。When including 3rd party libraries in your Xamarin.iOS app, you might get an error in the form "System.NotSupportedException: No data is available for encoding 437" when trying to compile and run the app. 例如,在操作过程中,库(如 Ionic.Zip.ZipFile)可能会引发此异常。For example, libraries, such as Ionic.Zip.ZipFile, may throw this exception during operation.

为此,可以打开 Xamarin 项目的选项,转到 " Ios 生成 > 国际化" 并查看 "西部" 国际化。This can be solved by opening the options for the Xamarin.iOS project, going to iOS Build > Internationalization and checking the West internationalization.