I have this really weird bug using LiteDB [1.0.4], when I try to make a Find that uses Contains I get a NullPointerException for every query but one.
My document is like this:
public class Index
{
public string FileId { get; set; }
public string AgreementId { get; set; }
public string AccountNumber { get; set; }
public string SortCode { get; set; }
public string FilePath { get; set; }
}
And my queries are as so:
var col = _db.GetCollection<Index>("index");
List<Index> query = new List<Index>();
switch (searchCriteria)
{
case "File ID":
query = col.Find(Query.Contains("FileId", searchText)).ToList();
break;
case "Agreement ID":
query = col.Find(Query.Contains("AgreementId", searchText)).ToList();
break;
case "Account Number":
query = col.Find(Query.Contains("AccountNumber", searchText)).ToList();
break;
case "Sort Code":
query = col.Find(Query.Contains("SortCode", searchText)).ToList();
break;
case "Account Number & Sort Code":
query = col.Find(Query.And(Query.EQ("AccountNumber", searchText), Query.EQ("SortCode", searchTextOpt))).ToList();
break;
default:
break;
}
The only one that goes though is with FileID, otherwise I get this exception.
Every field is EnsureIndex, I built the database several times.
This error also happens in the LiteDB Shell when doing something like:
db.index.find SortCode contains "59
Adding the stacktrace if it can help
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=LiteDB
StackTrace:
at LiteDB.QueryContains.<>c__DisplayClass1.<ExecuteIndex>b__0(IndexNode x)
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at LiteDB.LiteCollection`1.<Find>d__9.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at FasterPaymentsCOT.MainWindow.PerformSearch() in C:\Users\xxxx\MainWindow.xaml.cs:line 74
Hi @manny42, yes, it麓s a bug and was fixed, but I think that was publish only in v2-beta/rc. Is just a "half-line" fix :) [QueryContains.cs -> .Where(x => x.Key.IsString && x.Key.AsString.Contains(v))
This weekend I will generate 1.0.5 version to fix this.
Now it's fixed in v1.0.5 - it's on nuget
Most helpful comment
Hi @manny42, yes, it麓s a bug and was fixed, but I think that was publish only in v2-beta/rc. Is just a "half-line" fix :) [QueryContains.cs -> .Where(x => x.Key.IsString && x.Key.AsString.Contains(v))
This weekend I will generate 1.0.5 version to fix this.