-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
2 - S (<= 1 week)
-
1373
Hello:
This code was working on previous xamarin version , but now on Realm Xamarin 1.2 fails.
Goals
Execute a simple query like this:
T obj = realm.All<T>().OrderByDescending(x => x.Id).FirstOrDefault();
Expected Results
Get an object from database. This code was working on realm 1.1.1
<!--- What happened instead? -->
The query produces an exception
Error --> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.8.0.175/src/mono/mcs/class/referencesource/mscorlib/system/throwhelper.cs:68
at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00021] in ....
Steps to Reproduce
Create a simple class, and run the code.
Code Sample
public class Dog : RealmObject, IDocument { [PrimaryKey] public Int32 Id { get; set; } public string Name { get; set; } public int Age { get; set; } } public interface IDocument { Int32 Id { get; set; } } //code var realm = Realm.GetInstance(); realm.Write(() => { try { Int32 newId = NewId<Dog>(realm); realm.Add(new Dog { Id = newId, Name = "Rex", Age = 1 }); } catch(System.Exception ex) { Debug.WriteLine("Error --> " + ex.ToString()); } }); private Int32 NewId<T>( Realm realm) where T : Realms.RealmObject, IDocument { try { //this query gets an exception T obj = realm.All<T>().OrderByDescending(x => x.Id).FirstOrDefault(); if (obj == null) { return 1; } return obj.Id + 1; } catch (InvalidOperationException) { return 1; } }
Version of Realm and Tooling
Realm 1.2 Xamarin
Visual Studio 2017
Xamarin IOS
- Realm Object Server Version: none
- Flavor: Developer
- Server OS & Version: Windows 10
- Client SDK Version: Xamarin IOS SDK 10.8.0.174
- Client OS & Version: IOS 10.3