Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer中的NotImplementedException

时间:2014-04-18 17:23:13

标签: c# windows-phone-8

其他事情:n00b警告!

我正在尝试向本地存储写一些东西(至少我认为我是这样),但我得到的是NotImplementedException

正在使用WP 8.1预览构建(8.10.12359.845),但这似乎是 Not Implemented 的基本内容。

我一定做错了,但代码或多或少是 MSDN 教程所说的!

以下是代码:

class AccountStore
    {
        private const string ContainerAccountInfo = @"account";
        private const string KeyLastUpdated = "last_updated";
        private const string KeyUserId = "user_id";
        private const string KeyUsername = "user_name";
        private const string KeyEmail = "email";
        private const string KeyFullName = "full_name";
        private const string KeyStatus = "account_status";

        private static readonly object LOCK = new object();

        private ApplicationDataContainer Settings
        {
            get
            {
                // BOOM goes the code right here: System.NotImplementedException 
                return Windows.Storage.ApplicationData.Current.LocalSettings.CreateContainer(ContainerAccountInfo, ApplicationDataCreateDisposition.Always);
            }
        }

        public AccountInfo StoredAccountInfo {
            get {
                lock (LOCK)
                    {
                        var settings = Settings.Values;

                        if (settings.ContainsKey(KeyLastUpdated)) 
                        return new AccountInfo {
                            UserId = settings[KeyUserId] as string,
                            Username = settings[KeyUsername] as string,
                            Email = settings[KeyEmail] as string,
                            FullName = settings[KeyFullName] as string,
                            Status = AccountUtils.fromString(settings[KeyStatus] as string)
                        };

                        return AccountInfo.NULL;
                    }
            }

            set
            {
                lock (LOCK)
                {
                    var settings = Settings.Values;

                    settings[KeyLastUpdated] = DateTime.Now;
                    settings[KeyUserId] = value.UserId;
                    settings[KeyUsername] = value.Username;
                    settings[KeyEmail] = value.Email;
                    settings[KeyFullName] = value.FullName;
                    settings[KeyStatus] = value.Status.ToString();
                }
            }
        }
    }

System.NotImplementedException was unhandled by user code HResult=-2147467263 Message=The method or operation is not implemented. Source=Windows StackTrace: at Windows.Storage.ApplicationData.get_LocalSettings() at APPNS.Auth.detail.AccountStore.get_Settings() at APPNS.Auth.detail.AccountStore.get_StoredAccountInfo() at APPNS.Auth.AccountManager..ctor() at APPNS.Auth.AccountManager.get_Instance() at APPNS.Auth.AccountManager.get_Info() at APPNS.Auth.AccountManager.get_IsRegistered() at APPNS.MainPage.checkRegistration() at APPNS.MainPage.PhoneApplicationPage_Loaded(Object sender, RoutedEventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName) InnerException:

任何输入都表示赞赏。 我最近接触过C#大概是在5年前,我很生气。我也没有使用Windows Phone的经验(我是Android开发人员)。所以,如果我正在做一些完全愚蠢的事情,我也想知道这一点!

感谢。

1 个答案:

答案 0 :(得分:1)

您收到此错误是因为在Windows Phone 8.1之前未添加LocalSettingshttp://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localsettings.aspx

支持的最低手机 Windows Phone 8.1 [Windows Phone Silverlight 8.1和Windows运行时应用])

要使用它,您的构建目标必须是WP8.1或更高版本。