question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null propagation operator (?) and passing null values are failing

See original GitHub issue

Hi,

(1) Getting an exception when trying to use null propagation operator: DynamicExpresso.Exceptions.ParseException Neither of the types ‘null’ and ‘Boolean’ converts to the other (at index 31). This is in line (2) on Parse stage.

(2) Getting an exception when passing a null value via parameter class (line 2). Need to specify a type name as a second parameter one more time to work it out. Basically when using a name/value Parameter constructor will throw an exception if provided value is null, the other constructor (name/type/value) won’t throw. This behaviour is unclear because parameter type was already provided on Parse stage and looks like it should be possible just to provide a null value.


class Scope {
    public bool Value { get; set; }
}

var interpreter = new Interpreter();

(1) var func = interpreter.Parse("Scope?.Value == true", new Parameter("Scope", typeof(Scope)));
(2) var result = func.Invoke(new Parameter("Scope", typeof(Scope), null));

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
davideicardicommented, Oct 15, 2021

@halamah Just released v2.9.2

1reaction
metoulecommented, Oct 13, 2021

For the second issue, it’s because the Parameter class is used to declare both parameters (for which the type is required) and arguments (for which the type can be inferred from the Parameter). If the object value is null, there’s no way to detect its type, which is why an ArgumentNullException is thrown.

Note that you can directly invoke the lambda with the arguments’ values, without the need of creating Parameter instances:

var interpreter = new Interpreter();
var func = interpreter.Parse("Scope?.Value == true", new Parameter("Scope", typeof(Scope)));
var result = func.Invoke(null);
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Null propagation operator and extension methods
I've been looking at Visual Studio 14 CTP along with C# 6.0 and playing with the null-propagation operator. However, I couldn't find why...
Read more >
Async/Await Calls Gotcha with the CSharp ? Null Propagator
Let's break this down: The ? (Elvis) operator in C# propagates the null value in JsEditorInterop and short circuits the call to SetFocus()...
Read more >
The '= NULL' Mistake and other SQL NULL Heresies
The SQL Prompt Best Practice rule checks whether a comparison or expression includes a NULL literal ('NULL'), which in SQL Server, ...
Read more >
Null Propagation Operator and Unity (?) : r/Unity3D
The short answer is that the Null-Coalescing operator checks of it's actually null and doesn't call units overloaded Equals() operator like the ...
Read more >
c# - Is it unreasonable to expect Any() *not* to throw a null ...
isEmpty throws System.ArgumentNullException: Value cannot be null . The expectation seems to be that you won't be passing undefined values for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found