在我的 Xamarin Forms 应用中,我使用WCF数据服务更新,如下所示:
try { SRef.MyEntities entities = new SRef.MyEntities(new Uri(App.BaseURL)); DataServiceQuery query = (DataServiceQuery) entities.DataEntry.First(); query.BeginExecute((result) => { try { query.BeginExecute((result) => { try { var actData = query.EndExecute(result).FirstOrDefault(); if (actData != null) { actData.Info = "Info2"; entities.UpdateObject(actData); entities.BeginSaveChanges((result2) => { try { entities.EndSaveChanges(result2); } catch (Exception ex2) { Alert("Error: " + ex2.Message); } }, null); } } catch (Exception ex1) { Alert("Error: " + ex1.Message); } }, query); } catch (Exception ex) { Alert("Error: " + ex.Message); } });
运行时,我收到以下异常无法捕获且 EndSaveChanges 无法运行:
---- DEBUG ASSERTION FAILED ---- 03-16 09:59:22.057 D: DllImport attempting to load: '/system/lib/liblog.so'. [0:] ---- DEBUG ASSERTION FAILED ---- D: DllImport loaded library '/system/lib/liblog.so'. D: DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). D: Searching for '__android_log_print'. D: Probing '__android_log_print'. D: Found as '__android_log_print'. I: ---- DEBUG ASSERTION FAILED ---- [0:] ---- Assert Short Message ---- I: ---- Assert Short Message ---- [0:] Expected DateTimeOffset to be a UTC value. [0:] Expected DateTimeOffset to be a UTC value. I: Expected DateTimeOffset to be a UTC value. [0:] at System.Diagnostics.DefaultTraceListener.Fail(System.String message, System.String detailMessage) I: at System.Diagnostics.DefaultTraceListener.Fail(System.String message, System.String detailMessage) at System.Diagnostics.TraceListener.Fail(System.String message) at System.Diagnostics.DefaultTraceListener.Fail(System.String message) at System.Diagnostics.TraceImpl.Fail(System.String message) at System.Diagnostics.TraceImpl.Assert(Boolean condition, System.String message) at System.Diagnostics.Debug.Assert(Boolean condition, System.String message) at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToStringInternal(DateTime dateTime) at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToString(DateTime dateTime) at Microsoft.Data.OData.Atom.ODataAtomConvert.ToString(DateTime dt) at Microsoft.Data.OData.AtomValueUtils.TryConvertPrimitiveToString(System.Object value, System.String ByRef result) at Microsoft.Data.OData.AtomValueUtils.ConvertPrimitiveToString(System.Object value) at Microsoft.Data.OData.AtomValueUtils.WritePrimitiveValue(System.Xml.XmlWriter writer, System.Object value) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WritePrimitiveValue I: at System.Diagnostics.TraceListener.Fail(System.String message) [0:] at System.Diagnostics.DefaultTraceListener.Fail(System.String message, System.String detailMessage) at System.Diagnostics.TraceListener.Fail(System.String message) at System.Diagnostics.DefaultTraceListener.Fail(System.String message) at System.Diagnostics.TraceImpl.Fail(System.String message) at System.Diagnostics.TraceImpl.Assert(Boolean condition, System.String message) at System.Diagnostics.Debug.Assert(Boolean condition, System.String message) at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToStringInternal(DateTime dateTime) at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToString(DateTime dateTime) at Microsoft.Data.OData.Atom.ODataAtomConvert.ToString(DateTime dt) at Microsoft.Data.OData.AtomValueUtils.TryConvertPrimitiveToString(System.Object value, System.String ByRef result) at Microsoft.Data.OData.AtomValueUtils.ConvertPrimitiveToString(System.Object value) at Microsoft.Data.OData.AtomValueUtils.WritePrimitiveValue(System.Xml.XmlWriter writer, System.Object value) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WritePrimitiveValue(System.Object value, Microsoft.Data.OData.CollectionWithoutExpectedTypeValidator collectionValidator, IEdmTypeReference expectedTypeReference, Microsoft.Data.OData.SerializationTypeNameAnnotation typeNameAnnotation) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperty(Microsoft.Data.OData.ODataProperty property, IEdmStructuredType owningType, Boolean isTopLevel, Boolean isWritingCollection, System.Action beforePropertyAction, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmParentSourcePathSegment, Microsoft.Data.OData.DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperties(IEdmStructuredType owningType, IEnumerable`1 cachedProperties, Boolean isWritingCollection, System.Action beforePropertiesAction, System.Action afterPropertiesAction, Microsoft.Data.OData.DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomWriter.WriteEntryContent(Microsoft.Data.OData.ODataEntry entry, IEdmEntityType entryType, Microsoft.Data.OData.Atom.EntryPropertiesValueCache propertiesValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment rootSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomWriter.EndEntry(Microsoft.Data.OData.ODataEntry entry) at Microsoft.Data.OData.ODataWriterCore.b__16() at Microsoft.Data.OData.ODataWriterCore.InterceptException(System.Action action) at Microsoft.Data.OData.ODataWriterCore.WriteEndImplementation() at Microsoft.Data.OData.ODataWriterCore.WriteEnd() at System.Data.Services.Client.ODataWriterWrapper.WriteEnd(Microsoft.Data.OData.ODataEntry entry, System.Object entity) at System.Data.Services.Client.Serializer.WriteEntry(System.Data.Services.Client.EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateRequestData(System.Data.Services.Client.EntityDescriptor entityDescriptor, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.SaveResult.CreateNonBatchChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.SaveResult.BeginCreateNextChange() at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(SaveChangesOptions options, System.AsyncCallback callback, System.Object state) at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(System.AsyncCallback callback, System.Object state) at StefaniaXamarin.ViewModel.PaciensAdatokViewModel+c__DisplayClass4.b__1(IAsyncResult result) at System.Data.Services.Client.BaseAsyncResult.HandleCompleted() at System.Data.Services.Client.QueryResult.HandleCompleted(System.Data.Services.Client.PerRequest pereq) at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult) at System.Data.Services.Client.BaseAsyncResult.PostInvokeAsync(IAsyncResult asyncResult, System.AsyncCallback callback) at System.Data.Services.Client.BaseAsyncResult.InvokeAsync(System.Data.Services.Client.AsyncAction asyncAction, System.Byte[] buffer, Int32 offset, Int32 length, System.AsyncCallback callback, System.Object state) at System.Data.Services.Client.QueryResult.ReadResponseStream(System.Data.Services.Client.AsyncStateBag asyncStateBag) at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult) at System.Data.Services.Client.BaseAsyncResult+c__DisplayClass2.b__1(IAsyncResult asyncResult) at System.Net.SimpleAsyncResult+c__AnonStorey0.m__0(System.Net.SimpleAsyncResult result) at System.Net.SimpleAsyncResult.DoCallback_internal() at System.Net.WebAsyncResult.DoCallback() at System.Net.WebConnectionStream.ReadCallbackWrapper(IAsyncResult r) (System.Object value, Microsoft.Data.OData.CollectionWithoutExpectedTypeValidator collectionValidator, IEdmTypeReference expectedTypeReference, Microsoft.Data.OData.SerializationTypeNameAnnotation typeNameAnnotation) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperty(Microsoft.Data.OData.ODataProperty property, IEdmStructuredType owningType, Boolean isTopLevel, Boolean isWritingCollection, System.Action beforePropertyAction, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmParentSourcePathSegment, Microsoft.Data.OData.DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperties(IEdmStructuredType owningType, IEnumerable`1 cachedProperties, Boolean isWritingCollection, System.Action beforePropertiesAction, System.Action afterPropertiesAction, Microsoft.Data.OData.Dupl I: at System.Diagnostics.DefaultTraceListener.Fail(System.String message) icatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomWriter.WriteEntryContent(Microsoft.Data.OData.ODataEntry entry, IEdmEntityType entryType, Microsoft.Data.OData.Atom.EntryPropertiesValueCache propertiesValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment rootSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) at Microsoft.Data.OData.Atom.ODataAtomWriter.EndEntry(Microsoft.Data.OData.ODataEntry entry) at Microsoft.Data.OData.ODataWriterCore.b__16() at Microsoft.Data.OData.ODataWriterCore.InterceptException(System.Action action) at Microsoft.Data.OData.ODataWriterCore.WriteEndImplementation() at Microsoft.Data.OData.ODataWriterCore.WriteEnd() at System.Data.Services.Client.OData I: at System.Diagnostics.TraceImpl.Fail(System.String message) WriterWrapper.WriteEnd(Microsoft.Data.OData.ODataEntry entry, System.Object entity) at System.Data.Services.Client.Serializer.WriteEntry(System.Data.Services.Client.EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateRequestData(System.Data.Services.Client.EntityDescriptor entityDescriptor, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.SaveResult.CreateNonBatchChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) at System.Data.Services.Client.SaveResult.BeginCreateNextChange() at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(SaveChangesOptions options, System.AsyncCallback callback, System.Object state I: at System.Diagnostics.TraceImpl.Assert(Boolean condition, System.String message) ) at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(System.AsyncCallback callback, System.Object state) at StefaniaXamarin.ViewModel.PaciensAdatokViewModel+c__DisplayClass4.b__1(IAsyncResult result) at System.Data.Services.Client.BaseAsyncResult.HandleCompleted() at System.Data.Services.Client.QueryResult.HandleCompleted(System.Data.Services.Client.PerRequest pereq) at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult) at System.Data.Services.Client.BaseAsyncResult.PostInvokeAsync(IAsyncResult asyncResult, System.AsyncCallback callback) at System.Data.Services.Client.BaseAsyncResult.InvokeAsync(System.Data.Services.Client.AsyncAction asyncAction, System.Byte[] buffer, Int32 offset, Int32 length, System.AsyncCallback callback, System.Object state) at System.Data.Services.Client.QueryResult.ReadResponseStream(System.Data.Services.Client.AsyncStateBag asyncStateBag) at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResul I: at System.Diagnostics.Debug.Assert(Boolean condition, System.String message) t asyncResult) at System.Data.Services.Client.BaseAsyncResult+c__DisplayClass2.b__1(IAsyncResult asyncResult) at System.Net.SimpleAsyncResult+c__AnonStorey0.m__0(System.Net.SimpleAsyncResult result) at System.Net.SimpleAsyncResult.DoCallback_internal() at System.Net.WebAsyncResult.DoCallback() at System.Net.WebConnectionStream.ReadCallbackWrapper(IAsyncResult r) I: at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToStringInternal(DateTime dateTime) I: at Microsoft.Data.OData.PlatformHelper.ConvertDateTimeToString(DateTime dateTime) I: at Microsoft.Data.OData.Atom.ODataAtomConvert.ToString(DateTime dt) I: at Microsoft.Data.OData.AtomValueUtils.TryConvertPrimitiveToString(System.Object value, System.String ByRef result) I: at Microsoft.Data.OData.AtomValueUtils.ConvertPrimitiveToString(System.Object value) I: at Microsoft.Data.OData.AtomValueUtils.WritePrimitiveValue(System.Xml.XmlWriter writer, System.Object value) I: at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WritePrimitiveValue(System.Object value, Microsoft.Data.OData.CollectionWithoutExpectedTypeValidator collectionValidator, IEdmTypeReference expectedTypeReference, Microsoft.Data.OData.SerializationTypeNameAnnotation typeNameAnnotation) I: at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperty(Microsoft.Data.OData.ODataProperty property, IEdmStructuredType owningType, Boolean isTopLevel, Boolean isWritingCollection, System.Action beforePropertyAction, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmParentSourcePathSegment, Microsoft.Data.OData.DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) I: at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueSerializer.WriteProperties(IEdmStructuredType owningType, IEnumerable`1 cachedProperties, Boolean isWritingCollection, System.Action beforePropertiesAction, System.Action afterPropertiesAction, Microsoft.Data.OData.DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Microsoft.Data.OData.Atom.EpmValueCache epmValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment epmSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) I: at Microsoft.Data.OData.Atom.ODataAtomWriter.WriteEntryContent(Microsoft.Data.OData.ODataEntry entry, IEdmEntityType entryType, Microsoft.Data.OData.Atom.EntryPropertiesValueCache propertiesValueCache, Microsoft.Data.OData.Metadata.EpmSourcePathSegment rootSourcePathSegment, Microsoft.Data.OData.ProjectedPropertiesAnnotation projectedProperties) I: at Microsoft.Data.OData.Atom.ODataAtomWriter.EndEntry(Microsoft.Data.OData.ODataEntry entry) I: at Microsoft.Data.OData.ODataWriterCore.b__16() I: at Microsoft.Data.OData.ODataWriterCore.InterceptException(System.Action action) I: at Microsoft.Data.OData.ODataWriterCore.WriteEndImplementation() I: at Microsoft.Data.OData.ODataWriterCore.WriteEnd() I: at System.Data.Services.Client.ODataWriterWrapper.WriteEnd(Microsoft.Data.OData.ODataEntry entry, System.Object entity) I: at System.Data.Services.Client.Serializer.WriteEntry(System.Data.Services.Client.EntityDescriptor entityDescriptor, IEnumerable`1 relatedLinks, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) I: at System.Data.Services.Client.BaseSaveResult.CreateRequestData(System.Data.Services.Client.EntityDescriptor entityDescriptor, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) I: at System.Data.Services.Client.BaseSaveResult.CreateChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) I: at System.Data.Services.Client.SaveResult.CreateNonBatchChangeData(Int32 index, System.Data.Services.Client.ODataRequestMessageWrapper requestMessage) I: at System.Data.Services.Client.SaveResult.BeginCreateNextChange() I: at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(SaveChangesOptions options, System.AsyncCallback callback, System.Object state) I: at System.Data.Services.Client.DataServiceContext.BeginSaveChanges(System.AsyncCallback callback, System.Object state) I: at MyXamarinProject.ViewModel.MyViewModel+c__DisplayClass4.b__1(IAsyncResult result) I: at System.Data.Services.Client.BaseAsyncResult.HandleCompleted() I: at System.Data.Services.Client.QueryResult.HandleCompleted(System.Data.Services.Client.PerRequest pereq) I: at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult) I: at System.Data.Services.Client.BaseAsyncResult.PostInvokeAsync(IAsyncResult asyncResult, System.AsyncCallback callback) I: at System.Data.Services.Client.BaseAsyncResult.InvokeAsync(System.Data.Services.Client.AsyncAction asyncAction, System.Byte[] buffer, Int32 offset, Int32 length, System.AsyncCallback callback, System.Object state) I: at System.Data.Services.Client.QueryResult.ReadResponseStream(System.Data.Services.Client.AsyncStateBag asyncStateBag) I: at System.Data.Services.Client.QueryResult.AsyncEndRead(IAsyncResult asyncResult) I: at System.Data.Services.Client.BaseAsyncResult+c__DisplayClass2.b__1(IAsyncResult asyncResult) I: at System.Net.SimpleAsyncResult+c__AnonStorey0.m__0(System.Net.SimpleAsyncResult result) I: at System.Net.SimpleAsyncResult.DoCallback_internal() I: at System.Net.WebAsyncResult.DoCallback() I: at System.Net.WebConnectionStream.ReadCallbackWrapper(IAsyncResult r)它永远不会遇到任何问题。
造成这种情况的原因是什么?为什么catch块无法捕获异常?
答案 0 :(得分:0)
它没有抛出异常。它使用Debug.Assert()
方法失败了。
巧合的是,Debug.Assert()
在MessageBox中显示其输出,您可能会误认为Alert()
方法。
错误消息的相关区域:
I: ---- DEBUG ASSERTION FAILED ----
[0:]
---- Assert Short Message ----
I: ---- Assert Short Message ----
[0:]
Expected DateTimeOffset to be a UTC value.
[0:] Expected DateTimeOffset to be a UTC value.
I: Expected DateTimeOffset to be a UTC value.
[0:] at System.Diagnostics.DefaultTraceListener.Fail(System.String message, System.String detailMessage)
I: at System.Diagnostics.DefaultTraceListener.Fail(System.String message, System.String detailMessage)
at System.Diagnostics.TraceListener.Fail(System.String message)
at System.Diagnostics.DefaultTraceListener.Fail(System.String message)
at System.Diagnostics.TraceImpl.Fail(System.String message)
at System.Diagnostics.TraceImpl.Assert(Boolean condition, System.String message)
at System.Diagnostics.Debug.Assert(Boolean condition, System.String message)