Xamarin.iOS - System.Reflection.TargetInvocationException:调用目标抛出了异常

时间:2015-07-19 12:25:25

标签: xamarin.ios azure-mobile-services

当我将此代码添加到我的Xamarin.iOS应用程序中的viewController时:

public static MobileServiceClient MobileService = new MobileServiceClient(
            "https://test-database.azure-mobile.net/",
            "FxMRoOZYMaYFrJDZEhVOkziHEwzkqw26"
        );

我收到此错误:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

如何解决此错误?

这是我的整个ViewController:

using System;
using System.Drawing;
using Foundation;
using UIKit;
using Microsoft.WindowsAzure.MobileServices;

namespace MirrorMirror
{
    public partial class RootViewController : UIViewController
    {

        public static MobileServiceClient MobileService = new MobileServiceClient(
            "https://test-database.azure-mobile.net/",
            "FxMRoOZYMaYFrJDZEhVOkziHEwzkqw26"
        );

        //private readonly IMobileServiceTable<ToDoItem> ToDoTable = MobileService.GetTable<ToDoItem>();

        static bool UserInterfaceIdiomIsPhone
        {
            get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
        }

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

        public override void DidReceiveMemoryWarning()
        {
            // Releases the view if it doesn't have a superview.
            base.DidReceiveMemoryWarning();

            // Release any cached data, images, etc that aren't in use.
        }

        #region View lifecycle

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

    }

        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
        }

        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
        }

        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);
        }

        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);
        }

        #endregion

        partial void RefreshButton_TouchUpInside(UIButton sender)
        {
            var ToDo = new ToDoItem();
            ToDo.Text = "Buy Milk";
           // ToDoTable.InsertAsync(ToDo);
        }
    }
}

0 个答案:

没有答案