android - Xamarin 向导项目无法调试

标签 android ios xamarin xamarin.ios xamarin.android

所以一些背景信息。我的任务是探索使用 Xamarin 编写跨平台 native 应用程序。到目前为止看起来很基础,我喜欢我正在阅读的内容。我已经设置好我的 Visual Studio 2015 Enterprise,并在网络上配置了我的远程 mac。我通过 Visual Studio 中的项目创建向导创建了一个跨平台的原生应用程序。当我启动 iOS 应用程序的调试 session 时,它会在远程 Mac 的模拟器中启动目标应用程序。然而,它从未真正认为它正在完全运行。它会卡在这个输出:

Launching 'PersonalProject.iOS' on 'iPhone 6 iOS 10.2'...
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/Xamarin.iOS.dll
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.dll
Thread started:  #2
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/PersonalProject.iOS.exe
Loaded assembly: /Users/plm/Library/Developer/CoreSimulator/Devices/B5A038B6-056F-4E6C-A59C-29ABD8C04CD0/data/Containers/Bundle/Application/2A1B11FF-6C59-4A9B-9CE3-7B8446B1AD48/PersonalProject.iOS.app/System.Xml.dll

最终,它会因以下原因而失败:

The app has been terminated.
Launch failed. The app 'PersonalProject.iOS' could not be launched on 'iPhone 6 iOS 10.2'. Error: An error occurred while executing MTouch. Please check the logs for more details.

我已经检查了有问题的日志文件,它只包含完全相同的短语。

如果我尝试在按下按钮的操作上写一行简单的控制台:

    public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            // Perform any additional setup after loading the view, typically from a nib.
            Button.AccessibilityIdentifier = "myButton";
            Button.TouchUpInside += delegate {
                var title = string.Format ("{0} clicks!", count++);
                Button.SetTitle (title, UIControlState.Normal);
                Console.WriteLine(string.Format("{0} clicks!"));
            };
        }

调试 session 实际上在 Main.cs 文件的第 17 行 (UIApplication.Main) 上出错:

using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;

namespace PersonalProject.iOS
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main (string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
}

有未处理的异常错误:

Unhandled Exception:

System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Error while resolving expression: One or more errors occurred.

如果我没有控制台日志,它会启动应用程序,但仍会卡在那些已加载的装配线上。此时,我无法在我的代码中设置任何断点。我尝试在按钮单击的共享代码中添加一个断点,但它永远不会击中它,即使该操作是由模拟器执行的。

我完全不知道如何继续。我没有触及向导创建框外的任何内容。我希望我至少可以看到启动项目的工作。

感谢任何帮助。

最佳答案

你正在使用

Console.WriteLine(string.Format("{0} clicks!"));

{0} 是要输出的值的占位符,但您从未指定该值,这就是您收到错误的原因。

改用这样的东西:

Console.WriteLine(string.Format("{0} clicks!", count));

或者在 C#6 语法中:

Console.WriteLine($"{count} 次点击!");

关于android - Xamarin 向导项目无法调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42235340/

相关文章:

java - 尝试通过 JSON 查询从 openweathermap 获取数据时获取 FileNotFoundException

java - AssetManager 在 Assets 目录中找不到文件

ios - 是否可以强制 NSUbiquitousKeyValueStore 从云端提取更新?

java - 什么是 android logcat 中的致命信号 6

c# - Xamarin.IOS : UITableViewSource crashes on device

Android:ImageView 禁用缩放

java - SQLite 数据库没有被创建..为什么?

ios - 只使用一个 AVAudioPlayer 而不是三个

ios - 关于 Realm 数据库中的事务

xamarin - Xamarin 表单的出现中会发生什么?