简体   繁体   English

Xamarin.Forms - KeyNotFoundException: 字典中不存在给定的键 C#

[英]Xamarin.Forms - KeyNotFoundException: The given key was not present in the dictionary C#

I am using Xamarin.Forms and I getting this error:我正在使用 Xamarin.Forms 并且收到此错误:

KeyNotFoundException: The given key was not present in the dictionary KeyNotFoundException: 字典中不存在给定的键

For this line:对于这一行:

bool isLogin = (bool)Application.Current.Properties["isLogin"];

I tried to check to see if the key existed like so:我试图检查密钥是否存在,如下所示:

if(Application.Current.Properties.ContainsKey("isLogin"))
            {
                bool isLogin = (bool)Application.Current.Properties["isLogin"];

                string username = Application.Current.Properties["username"].ToString();

                if (isLogin)
                {
                    Application.Current.MainPage.Navigation.PushAsync(new MenuPage(), true);
                }
            }

But checking the key always returns false even after setting the key and value:但是即使在设置了键和值之后,检查键也总是返回 false:

Application.Current.Properties["isLogin"] = true;

Application.Current.Properties will be exists even if you kill the application and restart it again.即使您终止应用程序并重新启动它,Application.Current.Properties 也将存在。 Just try in this way unplug your device and try to login and check, it will work.只需尝试以这种方式拔下您的设备并尝试登录并检查,它就会工作。 While debugging it won't work.调试时它不起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#:KeyNotFoundException:字典中不存在给定的键 - C#: KeyNotFoundException: The given key was not present in the dictionary KeyNotFoundException:字典中不存在给定的键(C#Unity ANDROID APP) - KeyNotFoundException: The given key was not present in the dictionary (C# Unity ANDROID APP) x:Arguments Xamarin.Forms字典中不存在给定的键 - The given key was not present in the dictionary x:Arguments Xamarin.Forms KeyNotFoundException:字典中不存在给定的键 - KeyNotFoundException: The given key was not present in the dictionary KeyNotFoundException:字典中不存在给定的键 - KeyNotFoundException : The given key was not present in the dictionary System.Collections.Generic.KeyNotFoundException: '字典中不存在给定的键。' C# 窗口应用程序 - System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.' C# windows application NHibernate - KeyNotFoundException:给定的键不在字典中 - NHibernate - KeyNotFoundException: The given key was not present in the dictionary 鉴于字典Xamarin表单中不存在键 - Given Key Not Present in Dictionary Xamarin Forms C#Dictionary - 字典中没有给定的键 - C# Dictionary - The given key was not present in the dictionary KeyNotFoundException:字典中不存在给定的键“ OpenIdConnect.Code.RedirectUri” - KeyNotFoundException: The given key 'OpenIdConnect.Code.RedirectUri' was not present in the dictionary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM