Index Error "Object must be of type String"

508 views
Skip to first unread message

Steven Roberts

unread,
Apr 14, 2015, 5:47:31 PM4/14/15
to rav...@googlegroups.com
I'm getting the following index error in my Raven 2.5 (build 2956) database "Object must be of type String".  At first I thought this was an issue with the build version and indeed when I updated my build to 2956 and recreated the index it seemed to go away for a time.  Now it is back and I'm disappointed there's no more details about what object needs to be a string.  Here is my index

//maps
docs.Tenants.Select(tenant => new {
    TenantId = tenant.__document_id,
    Name = tenant.Name,
    IsActive = tenant.IsActive,
    TotalUsers = 0
})

//maps
docs.HierarchicalUserAccounts.Select(user => new {
    TenantId = (DynamicEnumerable.FirstOrDefault(user.Claims, x => x.Type == "tenant_id")).Value,
    Name = (this.LoadDocument((DynamicEnumerable.FirstOrDefault(user.Claims, x => x.Type == "tenant_id")).Value)).Name,
    IsActive = false,
    TotalUsers = 1
})

//reduce
results.OrderBy(result => result.Name).GroupBy(result => new {
    TenantId = result.TenantId,
    Name = result.Name
}).Select(g => new {
    TenantId = g.Key.TenantId,
    Name = g.Key.Name,
    IsActive = Enumerable.Any(g, x => x.IsActive),
    TotalUsers = Enumerable.Sum(g, x => ((int) x.TotalUsers))
})



Here is the error in it's entirety.

Here is a sample document that DOES show in the index
{
 
"Name": "tenant100",
 
"Licenses": 100,
 
"AdminId": "db08a33b-9a3f-4038-ae3d-dc3dc97318fa",
 
"IsActive": false,
 
"Applications": [
   
"csCM",
   
"csIM",
   
"csRA",
   
"csP&P",
   
"csGlobal"
 
],
 
"LogoUrl": null
}


and here is the one that does NOT show in the index
{
 
"Name": "some test tenant",
 
"Licenses": 10,
 
"AdminId": "e50ea0cc-10ef-432e-96d5-260173f86916",
 
"IsActive": true,
 
"Applications": [
   
"csCM",
   
"csIM",
   
"csRA",
   
"csP&P",
   
"csGlobal"
 
],
 
"LogoUrl": null
}

Any helps is greatly appreciated.  I'm sure this is something obvious to someone.


Oren Eini (Ayende Rahien)

unread,
Apr 14, 2015, 11:25:30 PM4/14/15
to ravendb
The error is here:

    Name = (this.LoadDocument((DynamicEnumerable.FirstOrDefault(user.Claims, x => x.Type == "tenant_id")).Value)).Name,

For some reason, you are sending a value which isn't a string into the LoadDocument call

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Roberts

unread,
Apr 15, 2015, 10:50:24 AM4/15/15
to rav...@googlegroups.com
I've double checked and that user "tenant_id" = "tenants/36".

This morning as I write to you, there is no more error.  I have made NO changes to that user or any other users for that matter.  In fact the index is showing "Last update of document: 10 hours ago".  Ugh, what is going on!?

Chris Marisic

unread,
Apr 15, 2015, 11:37:44 AM4/15/15
to rav...@googlegroups.com
Best guess, you're using FirstOrDefault, that you called LoadDocument(null) 

FirstOrDefault is always wrong. Stop using it.

Single() and SingleOrDefault() are meaningful, First() is barely tolerable but usually wrong.

Steven Roberts

unread,
Apr 15, 2015, 11:59:25 AM4/15/15
to rav...@googlegroups.com
FirstOrDefault is always wrong. Stop using it.
I agree, but this sample was from Oren so that's what I used.  in any case it doesn't really explain how the null was passed as the item exists in the collection (always) and is never null 

Chris Marisic

unread,
Apr 16, 2015, 11:09:31 AM4/16/15
to rav...@googlegroups.com


On Wednesday, April 15, 2015 at 10:59:25 AM UTC-5, Steven Roberts wrote:
FirstOrDefault is always wrong. Stop using it.
I agree, but this sample was from Oren so that's what I used.  in any case it doesn't really explain how the null was passed as the item exists in the collection (always) and is never null 

I'm going to say it WAS null and your expectations were violated. 

Steven Roberts

unread,
Apr 20, 2015, 8:11:08 PM4/20/15
to rav...@googlegroups.com
Ok I'm getting this error again.  No my expectation are not violated.  I've just now created the tenant object AND the user object and the user does have a tenant_id in the claims.  Per the image in the previous post the error appears to be in the Reduce portion of the Index.  Is there anything else I can do to troubleshoot this.

Steven Roberts

unread,
Apr 20, 2015, 8:16:38 PM4/20/15
to rav...@googlegroups.com
An additional point.  In this new database there is only 1 tenant and one user and the details are properly returned in the index now but it still shows an error

Here is the stack trace from the log
System.ArgumentException: Object must be of type String.
   at System.String.CompareTo(Object value)
   at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
   at System.Linq.EnumerableSorter`1.QuickSort(Int32[] map, Int32 left, Int32 right)
   at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Raven.Database.Indexing.RobustEnumerator.MoveNext(IEnumerator en, StatefulEnumerableWrapper`1 innerEnumerator)

Oren Eini (Ayende Rahien)

unread,
Apr 21, 2015, 4:18:30 AM4/21/15
to ravendb
Okay, that is much better now.

The issue is here:
.OrderBy(result => result.Name)

Remove that, it has no effect whatsoever.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--

Steven Roberts

unread,
Apr 21, 2015, 9:02:10 AM4/21/15
to rav...@googlegroups.com
Ok thank you, I will try that.  Still seems odd it would give a null reference
Reply all
Reply to author
Forward
0 new messages