You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, I am trying to implement a maybe weird case in my internal project. The basic concept is that any JSON object can be part of a JSON array.
So something like that:
[
{
"animal": "cat"
},
{
"color": "green"
}
]
If I now try to run something like that:
JsonDocumentdata=null;// something sets the value of JsonDocument so it's not nulldata.Any(config:System.Linq.Dynamic.Core.SystemTextJson.Config.SystemTextJsonParsingConfig.Default,"x => x.number == 5"));
I will now get an exception like that:
The binary operator Equal is not defined for the types 'System.Object' and 'System.Int32'.
My question is, is there some kind of expression that I can write, that makes it possible to make a member optional?
However, I would expect that when you try to query an non-existing member, you would get error like: Unhandled exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'xxx' does not contain a definition for 'number'
I did fix the code so that your unit tests pass. However you will need to provide ConvertObjectToSupportComparison = true and missing members are not yet supported.
Activity
StefH commentedon Oct 25, 2025
@paule96
Maybe you can try this:
https://dynamic-linq.net/advanced-configuration#allowequalsandtostringmethodsonobject-since-v1.6.0
add test cases for not exsisting members in where clause (zzzprojects…
paule96 commentedon Oct 30, 2025
@StefH
We tried this but it doesn't help us.
But I created reproduction tests with the commit:
paule96@c0b8e02
The following tests are falling:
notExisting > 1)notExisting == true)Comparing to strings are just working
[-]How to handle not existing member[/-][+]SystemTextJson: How to handle not existing member[/+]StefH commentedon Nov 1, 2025
@paule96
OK, thanks for the unit tests.
However, I would expect that when you try to query an non-existing member, you would get error like:
Unhandled exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'xxx' does not contain a definition for 'number'paule96 commentedon Nov 1, 2025
Yes I would expect the same for the default path.
But also when you work with json, it's kinda normal to miss members.
So it would be nice to have a syntax or a configuration that allows to compare to non existing members.
[-]SystemTextJson: How to handle not existing member[/-][+]Json: How to handle not existing member[/+]StefH commentedon Nov 2, 2025
#954
StefH commentedon Nov 2, 2025
I did fix the code so that your unit tests pass. However you will need to provide
ConvertObjectToSupportComparison = trueand missing members are not yet supported.paule96 commentedon Nov 3, 2025
very cool thank you. We will try it out the next days
StefH commentedon Nov 5, 2025
I will probably create new version this weekend
paule96 commentedon Nov 10, 2025
@StefH we found one scenario that may produce invalid results. But it's a bit hard to decide because we are in a world between JSON and C#.
x.notExsting == falseThis currently returns
true. But actually, because in JS/JSON worldx.notExstingis undefined and not false, it should return false.StefH commentedon Nov 10, 2025
What if you compare with a nullable bool with value false?
paule96 commentedon Nov 10, 2025
How do you mean? From a plain C# view like that:
The result would be
Hello false.paule96 commentedon Nov 13, 2025
@StefH ping :)
StefH commentedon Nov 14, 2025
I will take a look this weekend.
Probably I will add a bool config setting with default to true to normalize the json.
StefH commentedon Nov 15, 2025
This PR should solve this:
#958
paule96 commentedon Nov 15, 2025
Very cool. Will try ut next week