Skip to content

Error trying to resolve field 'value'. #82

@alireza-salehi

Description

@alireza-salehi

"path": [
"products",
"items",

"extensions": {
"code": "INVALID_CAST",
"details": "GraphQL.Execution.UnhandledError: Error trying to resolve field 'value'.\r\n ---> System.InvalidCastException: Unable to cast object of type 'System.Double' to type 'System.Decimal'.\r\n at VirtoCommerce.XCatalog.Core.Schemas.PropertyType.ResolveValue(Property source, String languageCode) in /home/runner/work/vc-module-x-catalog/vc-module-x-catalog/src/VirtoCommerce.XCatalog.Core/Schemas/PropertyType.cs:line 124\r\n at GraphQL.Execution.ExecutionStrategy.ExecuteNodeAsync(ExecutionContext context, ExecutionNode node) in //src/GraphQL/Execution/ExecutionStrategy.cs:line 516\r\n --- End of inner exception stack trace ---"

The Problem:

The backend stores property values as object type
For numeric values, they're stored as System.Double
Line 124 tries to directly cast (decimal)propertyValue.Value
C# doesn't allow direct casting from double to decimal - you need to use Convert.ToDecimal()
How to Fix in Backend:
change this:
var decimalValue = (decimal)propertyValue.Value;
to this:
var decimalValue = Convert.ToDecimal(propertyValue.Value);

https://github.com/VirtoCommerce/vc-module-x-catalog/blob/master/src/VirtoCommerce.XCatalog.Core/Schemas/PropertyType.cs line 124

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions