2

我有一个带有 ListView 的 Xamarin XAML 页面。列表数据源链接到一个可观察的集合,该集合填充了领域对象。

当我尝试从 ListView 中删除一个对象(首先从数据源然后从领域)我遇到了崩溃。

崩溃仅在 iOS 绑定时发生,内部异常消息是:

此对象已分离。是从领域中删除的吗?

因此,似乎删除后仍然从 ListView 访问该对象。

堆栈跟踪:

  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00050] in /Users/builder/data/lanes/3818/3983064a/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:313 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builder/data/lanes/3818/3983064a/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/referencesource/mscorlib/system/reflection/methodbase.cs:229 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.TryGetValue (System.Object source, System.Object& value) [0x00043] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:498 
  at Xamarin.Forms.BindingExpression.Unapply () [0x00030] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindingExpression.cs:90 
  at Xamarin.Forms.Binding.Unapply () [0x0000e] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Binding.cs:142 
  at Xamarin.Forms.BindableObject.ApplyBindings (System.Object oldContext, System.Boolean skipBindingContext) [0x0002e] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:407 
  at Xamarin.Forms.BindableObject.ApplyBindings (System.Object oldContext) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:123 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:117 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:472 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:322 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00061] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:118 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:472 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:322 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.Grid.OnBindingContextChanged () [0x00006] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Grid.cs:139 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00061] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:118 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:472 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:322 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.Grid.OnBindingContextChanged () [0x00006] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Grid.cs:139 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00061] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:118 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:472 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Element.cs:322 
  at Xamarin.Forms.Cell.OnBindingContextChanged () [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\Cells\Cell.cs:117 
  at Xamarin.Forms.BindableObject.BindingContextPropertyBindingPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x0001b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:429 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.BindableObject+SetValueFlags attributes, System.Boolean silent) [0x00108] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:584 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.BindableObject+SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0014b] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:378 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0005f] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:531 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:83 
  at Xamarin.Forms.BindableObject.set_BindingContext (System.Object value) [0x00000] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\BindableObject.cs:24 
  at Xamarin.Forms.TemplatedItemsList`2+<UnhookItem>d__153[TView,TItem].MoveNext () [0x000a7] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Core\TemplatedItemsList.cs:1210 

内部异常堆栈跟踪:

  at Realms.NativeException.ThrowIfNecessary (System.Func`2[T,TResult] overrider) [0x00014] in <fb8acf22c75e4f8ba1fe5f730039e63b>:0 
  at Realms.RowHandle.get_RowIndex () [0x00009] in <fb8acf22c75e4f8ba1fe5f730039e63b>:0 
  at Realms.RealmObject.GetObjectValue[T] (System.String propertyName) [0x00000] in <fb8acf22c75e4f8ba1fe5f730039e63b>:0 
  at TestProject.StockApp.Data.ManagedObjects.ArticleEntity.get_Article () [0x00006] in <bc12041acc564a39b37d8658934e3bc3>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Users/builder/data/lanes/3818/3983064a/source/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305

更新

似乎只有在 ListView 中使用的领域对象具有也显示到 ListView 单元格的关系时才会发生错误。

例如,如果我有一个 Dogs 列表,但在单元格中我还显示 Owner .FirstName,那么当我删除选定的狗项时会发生崩溃。

public class Dog : RealmObject 
{
    public string Name { get; set; }
    public int Age { get; set; }
    public Person Owner { get; set; }
}

public class Person: RealmObject 
{
    public string FirstName{ get; set; }
}
4

2 回答 2

1

列表数据源链接到一个可观察的集合,该集合填充了领域对象

那个可观察的集合是如何更新的?

堆栈跟踪在 Forms 中很深 - 看起来这是他们代码工作方式的一个怪癖 - 你能否将源代码发送到 support@realm.io,我会看看它。

于 2016-09-28T10:42:08.757 回答
0

As of v0.81.0, RealmObject is implicitly an ObservableObject such that it fires INotifyPropertyChanged on properties and INotifyCollectionChanged on IList and IQueryable properties.

For more info:

于 2017-06-24T23:55:30.817 回答