Xamarin向导项目无法调试

时间:2017-02-14 20:12:05

标签: android ios xamarin xamarin.ios xamarin.android

所以一些背景资料。我的任务是探索使用Xamarin编写跨平台本机应用程序。到目前为止似乎很基本,我喜欢我正在读的东西。我安装了Visual Studio 2015 Enterprise,并在网络上配置了远程mac。我通过Visual Studio中的项目创建向导创建了一个跨平台的本机应用程序。当我为iOS应用程序启动调试会话时,它会在远程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!"));
            };
        }

调试会话实际上在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.

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

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

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您正在使用

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

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

使用类似的东西:

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

或C#6语法:

Console.WriteLine($"{count} clicks!");

相关问题