【发布时间】:2018-03-13 12:35:45
【问题描述】:
我的 xamarin 应用程序上的注册和登录功能突然停止工作。它有时会给出:
未处理的异常:Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException:发生
其他时间:
未处理的异常:Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException:无法完成请求。 (内部服务器错误)发生
我没有更改这些页面上的任何内容来影响它们。唯一发生的事情是我的 azure 订阅过期了,我更新了它。除非我缺少某些设置,否则连接仍然相同。
我确定这两个页面上的问题是相同的,所以我将在此处显示我的注册页面。如果您需要查看我的登录信息,请告诉我。
编辑 1:我添加了一个 try/catch,它总是会被捕获。
编辑 2:应用程序可能在其主线程上做了太多工作。
这出现在日志中,不知道为什么它突然不断给出这些异常,我尝试没有任何改善。
编辑 3:尝试干净构建、卸载、重新安装,但现在我不知所措。到今天为止它运行良好,现在我遇到了上面提到的这些问题,但我似乎没有任何办法解决它。
EditText Username = FindViewById<EditText>(Resource.Id.txtUsername);
EditText Password = FindViewById<EditText>(Resource.Id.txtPassword);
EditText ConfirmPassword = FindViewById<EditText>(Resource.Id.txtConfirmPassword);
if (Password.Text == ConfirmPassword.Text)
{
try
{
string hashedPassword = PasswordStorage.CreateHash(Password.Text);
string userName = Username.Text.Trim();
users newU = new users { username = userName, password = hashedPassword };
List<users> allUsers = await Client.GetTable<users>().ToListAsync();
Toast.MakeText(this, "Awaits table", ToastLength.Short).Show();
users u = allUsers.FirstOrDefault(x => x.username == newU.username);
if (u == null)
{
DBHelper.InsertNewUser(newU);
Toast.MakeText(this, "User " + newU.username + " created! You can now log in!", ToastLength.Short).Show();
StartActivity(typeof(MainActivity));
}
else
{
Toast.MakeText(this, "User " + u.username + " already exists!", ToastLength.Short).Show();
}
}
catch (Exception)
{
Toast.MakeText(this, "Time out", ToastLength.Short).Show();
}
}
【问题讨论】:
-
对于移动应用程序,您必须假设到服务器的连接可能在任何给定时间都无法正常工作。在设备上使用分布式数据库非常糟糕,这可能是必要的。总的来说,这些 Excpetitions 在本质上听起来很简单。您应该处理的罕见情况。但我不能 100% 排除他们不是 Boneheaded 而不是。这里有两篇关于正确异常处理的文章,我链接了很多。 blogs.msdn.com/b/ericlippert/archive/2008/09/10/… | codeproject.com/Articles/9538/…
标签: c# azure xamarin azure-mobile-services