gpt4 book ai didi

c# - InsertAsync 时 Azure 移动应用程序服务异常 "The item does not exist"

转载 作者:太空宇宙 更新时间:2023-11-03 23:13:35 26 4
gpt4 key购买 nike

我有兴趣的情况。我在 Azure 上有类和表格:

public class InmeItem
{
public string Id { get; set; }
[JsonProperty(PropertyName = "heartrate")]
public string Heartrate { get; set; }
[JsonProperty(PropertyName = "pulsewave")]
public string Pulsewave { get; set; }
}

我有以下代码将新项目插入表中:

public static async Task InsertInmeItem(InmeItem inmeitem)
{
try
{
await App.MobileService.GetTable<InmeItem>().InsertAsync(inmeitem);
}

catch (Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException ex)
{
Debug.WriteLine("This is f***** situation which post data but generate exception: " + ex.ToString());
}

catch (Exception ex)
{
Debug.WriteLine(ex);
}
}

但我有一些感兴趣的情况 - 运行抛出异常“该项目不存在”,但数据已插入到 Azure 上的表中,没有任何异常

异常信息:

This is f***** situation which post data  but generate exception: Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The item does not exist
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<ThrowInvalidResponse>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<SendRequestAsync>d__1d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<RequestAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<>c__DisplayClass14.<<InsertAsync>b__13>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<TransformHttpException>d__4d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<InsertAsync>d__1a.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<TransformHttpException>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<InsertAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<InsertAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at InmeTesting.Models.Backoffice.<InsertInmeItem>d__2.MoveNext()

最佳答案

您需要确保从插入函数返回正确的结果,即它希望您返回插入的项目。您不一定需要返回插入的项目,但必须返回一些内容以呈现给客户端,否则框架将返回 404,并显示消息“该项目不存在”。

第一个示例成功,因为 context.execute 返回插入的项目。在第二个示例中,该项目显然不是从 .then() 调用中的代码块返回的。

关于c# - InsertAsync 时 Azure 移动应用程序服务异常 "The item does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38075903/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com