"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type" during Index Creation

1,208 views
Skip to first unread message

Shubha Lakshmi

unread,
Oct 19, 2017, 6:20:57 AM10/19/17
to RavenDB - 2nd generation document database
I am trying to create a simple index, something  like this :

 
public class Services_ByAll : AbstractIndexCreationTask<Service, Services_ByAll.Result>
   
{
       
       
public class Result
       
{

             
public string MyFieldOne{get;set;}
             
public string MyFieldTwo{get;set;}
             
public string MyFieldThree{get;set;}
             
public string MyFieldFour{get;set;}

       
}

       
public Services_ByAll()
       
{
           
Map = (services) => from service in services
                                let arg1
= service.MyFieldOne.Split('-').Aggregate((i, j) => i + " " + j)
                                let arg2
= service.MyFieldThree.Split('-').Aggregate((i, j) => i + " " + j)
                               
                               
select new Result
                               
{
                                   
                                     
MyFiledOne = service.MyFieldOne,
                                     
MyFieldThree =service.MyFieldThree,
                                     
MyFieldTwo = arg1,
                                     
MyFieldFour = arg2

                               
};
           
//Make text fields as Analyzed, in order to enable full text search on them


           
Indexes.Add(entry => entry.MyFieldTwo, FieldIndexing.Analyzed);
           
Indexes.Add(entry => entry.MyFieldFour, FieldIndexing.Analyzed);
           


           
Analyzers.Add(x => x.MyFieldTwo, typeof(StandardAnalyzer).AssemblyQualifiedName);
           
Analyzers.Add(x => x.MyFieldFour, typeof(StandardAnalyzer).AssemblyQualifiedName);    


       
}
   
}


However, When I am running the application, I am getting a run time exception that "Error CS1977 - Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type".
Any pointers would help.
TIA

Mrinal Kamboj

unread,
Oct 19, 2017, 6:56:11 AM10/19/17
to RavenDB - 2nd generation document database
Can you paste the code which is using this index internally, thus leading to exception. There's a possibility of not creating the Expression tree correctly.

Shubha Lakshmi

unread,
Oct 19, 2017, 7:14:43 AM10/19/17
to RavenDB - 2nd generation document database
Not Sure, because it is run-time generated error.
Posting partial Stack Trace here :
15:19:14, Error, InnerExceptionMessage :: 1 :: Failed to compile index name = Services/ByAll :: ,
15:19:14, Error, InnerExceptionSource :: 1 :: :: ,
15:19:14, Error, InnerExceptionStackTrace :: 1 :: :: ,
15:19:14, Error, InnerExceptionMessage :: 2 :: Compilation Errors: Line 75, Position 9: Error CS1977 - Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

Oren Eini (Ayende Rahien)

unread,
Oct 19, 2017, 7:23:17 AM10/19/17
to ravendb
Use:

                                let arg1 = service.MyFieldOne.Replace('-', ' ').
Or:
                                let arg1 = string.Join(" " , service.MyFieldOne.Split('-'))

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shubha Lakshmi

unread,
Oct 19, 2017, 7:36:30 AM10/19/17
to RavenDB - 2nd generation document database
Thanks Oren , that worked! But I am not able to understand what is the difference between 
service.MyFieldOne.Split('-').Aggregate((i, j) => i + " " + j)
and 
 service.MyFieldOne.Replace('-',' ')

I mean what caused the exception to go away ...
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Oct 19, 2017, 7:45:36 AM10/19/17
to ravendb
The issue is that Aggregate isn't recognized on the server side, which cause the issue
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages