You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Im currently working with Realm (Database) in my Application. In Realm Objects you use an IList for a List of nested Objects:
Example: public class DemoObject:RealmObject { [MapTo("nestedObjects")] public IList<NestedObject> Nested { get; } }
The Problem is that Realm replaces this IList with an IRealmCollection which does not implement IList. Instead it implements IReadOnlyList, IEnumerable, IEnumerable, IReadOnlyCollection, INotifyCollectionChanged, NotifyPropertyChanged.
So when you modify the IRealmCollection by adding an Item and the EventHandler CollectionChanged is triggered, the CollectionViewRenderer for iOS tries to cast _itemSource to IList in line 409. The cast then throws the SystemInvalidCastException.
Would it be possible to check if _itemSource can be casted to an IList and if not an IEnumerable is used instead?
For example something like:
var count = 0;
if(_itemSource is IList list){
count = list.Count;
}else{
var enumerator = _itemSource.GetEnumerator();
while(enumerator.MoveNext()){
count +=1;
}
if(Control.NumberOfItemsInSection(0) == count){
return;
}
Thanks for any help in advance :)
StackTrace:
at Sharpnado.CollectionView.iOS.Renderers.CollectionViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in D:\Dev\Sharpnado\src\Sharpnado.HorizontalListView\Sharpnado.CollectionView.iOS\Renderers\CollectionViewRenderer.cs:409
at Realms.RealmCollectionBase1[T].RaiseCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:343 at Realms.RealmCollectionBase1[T].OnChange (Realms.IRealmCollection1[T] sender, Realms.ChangeSet change, System.Exception error) [0x00205] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:334 at Realms.RealmCollectionBase1[T].Realms.INotifiable<Realms.NotifiableObjectHandleBase.CollectionChangeSet>.NotifyCallbacks (System.Nullable1[T] changes, System.Nullable1[T] exception) [0x00162] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:412
at Realms.NotifiableObjectHandleBase.NotifyObjectChanged (System.IntPtr managedHandle, System.IntPtr changes, System.IntPtr exception) [0x00017] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Handles\NotifiableObjectHandleBase.cs:62
at (wrapper native-to-managed) Realms.NotifiableObjectHandleBase.NotifyObjectChanged(intptr,intptr,intptr)
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.scheduler_invoke_function(intptr,bool)
at Realms.SynchronizationContextScheduler+Scheduler.b__4_0 (System.Object f_ptr) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Native\SynchronizationContextScheduler.cs:68
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.scheduler_invoke_function(intptr,bool)
at Realms.SynchronizationContextScheduler+Scheduler.b__4_0 (System.Object f_ptr) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Native\SynchronizationContextScheduler.cs:68
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:69
at KiloForKilo.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\janni\source\repos\KiloForKilo\KiloForKilo\KiloForKilo.iOS\Main.cs:12
The text was updated successfully, but these errors were encountered:
meierhoeferjannis
added a commit
to meierhoeferjannis/Sharpnado.CollectionView
that referenced
this issue
Dec 16, 2021
Hi, just wanted to know if you had the time to review my Pull request on this issue. Would be cool if you could do it and release a new fixed version of the collection view :)
Describe the bug
Im currently working with Realm (Database) in my Application. In Realm Objects you use an IList for a List of nested Objects:
Example:
public class DemoObject:RealmObject { [MapTo("nestedObjects")] public IList<NestedObject> Nested { get; } }
The Problem is that Realm replaces this IList with an IRealmCollection which does not implement IList. Instead it implements IReadOnlyList, IEnumerable, IEnumerable, IReadOnlyCollection, INotifyCollectionChanged, NotifyPropertyChanged.
So when you modify the IRealmCollection by adding an Item and the EventHandler CollectionChanged is triggered, the CollectionViewRenderer for iOS tries to cast _itemSource to IList in line 409. The cast then throws the SystemInvalidCastException.
Would it be possible to check if _itemSource can be casted to an IList and if not an IEnumerable is used instead?
For example something like:
Thanks for any help in advance :)
StackTrace:
at Sharpnado.CollectionView.iOS.Renderers.CollectionViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00012] in D:\Dev\Sharpnado\src\Sharpnado.HorizontalListView\Sharpnado.CollectionView.iOS\Renderers\CollectionViewRenderer.cs:409
at Realms.RealmCollectionBase
1[T].RaiseCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:343 at Realms.RealmCollectionBase
1[T].OnChange (Realms.IRealmCollection1[T] sender, Realms.ChangeSet change, System.Exception error) [0x00205] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:334 at Realms.RealmCollectionBase
1[T].Realms.INotifiable<Realms.NotifiableObjectHandleBase.CollectionChangeSet>.NotifyCallbacks (System.Nullable1[T] changes, System.Nullable
1[T] exception) [0x00162] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\DatabaseTypes\RealmCollectionBase.cs:412at Realms.NotifiableObjectHandleBase.NotifyObjectChanged (System.IntPtr managedHandle, System.IntPtr changes, System.IntPtr exception) [0x00017] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Handles\NotifiableObjectHandleBase.cs:62
at (wrapper native-to-managed) Realms.NotifiableObjectHandleBase.NotifyObjectChanged(intptr,intptr,intptr)
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.scheduler_invoke_function(intptr,bool)
at Realms.SynchronizationContextScheduler+Scheduler.b__4_0 (System.Object f_ptr) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Native\SynchronizationContextScheduler.cs:68
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) Realms.SynchronizationContextScheduler.scheduler_invoke_function(intptr,bool)
at Realms.SynchronizationContextScheduler+Scheduler.b__4_0 (System.Object f_ptr) [0x00000] in D:\a\realm-dotnet\realm-dotnet\Realm\Realm\Native\SynchronizationContextScheduler.cs:68
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:69
at KiloForKilo.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\janni\source\repos\KiloForKilo\KiloForKilo\KiloForKilo.iOS\Main.cs:12
The text was updated successfully, but these errors were encountered: