Try our conversational search powered by Generative AI!

[ProjectionException: An exception of type InvalidCastException was thrown while projecting field Price$$number.]

Vote:
 

Lately and seems only in development indexes we get following exception:

[InvalidCastException: Specified cast is not valid.]
   EPiServer.Find.ProjectionHelper.ReplaceExpressionWithConstantFromField(Dictionary`2 args, Expression expression) +1030

[ProjectionException: An exception of type InvalidCastException was thrown while projecting field Price$$number.]
   EPiServer.Find.ProjectionHelper.ReplaceExpressionWithConstantFromField(Dictionary`2 args, Expression expression) +2395
   EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitMemberAssignment(MemberAssignment assignment) +40
   EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitBinding(MemberBinding binding) +116
   EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitBindingList(ReadOnlyCollection`1 original) +92
   EPiServer.Find.Helpers.Linq.ExpressionVisitor.VisitMemberInit(MemberInitExpression init) +50
   EPiServer.Find.Helpers.Linq.ExpressionVisitor.Visit(Expression exp) +759
   EPiServer.Find.ProjectionHelper.ReplaceMemberAssignmentsWithFieldValues(Expression selector, Dictionary`2 args) +262
   EPiServer.Find.ProjectionHelper.GetMappedSearchResultItem(SearchRequestBody requestBody, SearchHit`1 searchHit) +342
   EPiServer.Find.ProjectionHelper.GetMappedResult(SearchRequestBody requestBody, SearchResults`1 jsonResult) +729
   EPiServer.Find.SearchExtensions.GetProjectedResult(ISearch`1 search, SearchContext context) +575
   EPiServer.Find.SearchExtensions.GetResult(ISearch`1 search) +645

Property in question is defined as follows:

public decimal Price { get; set; }

Mostly it contains price that has only 0 after decimal point, for example 189 and not 189.01

So when 'EPiServer Find Content Indexing Job' is ran following can be observed, in Fiddler, for example:

 
POST https://es-eu-dev-api01.episerver.net/xxxxx/_bulk HTTP/1.1
.....
.....
.....
,"Price$$number":907500.0,
.....
.....
.....

Note that it has: .0

When this very same object is retrieved from Episerver Find, its sent back as:

POST https://es-eu-dev-api01.episerver.net/xxxx/gatisb_site/_search HTTP/1.1



response:
.....
.....
.....
,"Price$$number":907500,
.....
.....
.....

So what happens next is JSON deserializer treats this field now as long and not as double or decimal

Leading to this:

full image

example

JSON parser does its best and as there are no trailing .0(no decimal point) it interprets that as long, leading later to InvalidCastException as casting object{long} to decimal fails

So why did Episerver Find omit .0, seems to be only happening for dev indexes and not production ones

Are we doing something wrong in multiple projects or is this Episerver Find issue?

Find version 12.3.1 or 12.4.0

#176348
Edited, Mar 16, 2017 15:06
Vote:
 

I can confirm that it works now on, if reindex is done:

es-eu-dev-api01.episerver.net

So EPiServer what was wrong and how did you fix it?

#176478
Mar 20, 2017 11:55
Vote:
 

It was a problem in the Proxy that has been fixed.

#176488
Mar 20, 2017 12:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.