-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
np (NullPropagation) throws NullReferenceException with methods #302
Comments
For now it can only work on properties. (Updated the info on https://github.com/StefH/System.Linq.Dynamic.Core/wiki/NullPropagation) I'll take a look if it can be updated for methods... |
Please try MyGet preview version : System.Linq.Dynamic.Core.1.0.19-ci-11874 |
I am attempting to add the feed to LINQPad and test. I see v1.0.18 in MyGet and 1.0.19 in Nuget. Either one seems to give me the same error. |
Did you try that exact version? |
@NetMage Did you have time to test? |
@NetMage Can you please verify ? |
@NetMage can you please test if this version does fix your issue? |
So I figured out how to get it in LINQPad and tried it. Instead of a null reference exception I now get a ParseException: The 'np' (null-propagation) function requires the first argument to be a MemberExpression Is that what should happen? |
Can you provide a full working example? Because when I run these tests"https://github.com/StefH/System.Linq.Dynamic.Core/pull/309/files#diff-26864b997e03a24c9676bd97c489ac76R1308 It works as expected. |
When I execute the following in LINQPad, or in a VS2019 Console Program using ci-12228 installed, I get a Null Reference Exception on the void Main() {
var defaultRoleName = "x";
var users = new[] { new User { Roles = new List<Role>() } }.AsQueryable();
// Act
var resultDynamic = users.Select("np(Roles.FirstOrDefault(false).Name, @0)", defaultRoleName).ToDynamicArray();
resultDynamic.Dump();
}
// Define other methods, classes and namespaces here
public interface IEntity {
long Id { get; set; }
}
public abstract class Entity : IEntity {
public long Id { get; set; }
}
public class User : Entity {
public string IdentityName { get; set; }
public string DisplayName { get; set; }
public string EmailAddress { get; set; }
public ICollection<Role> Roles { get; set; }
public bool HasRole(string role) {
return Roles.Any(r => r.Name == role);
}
}
public class Role : Entity {
public string Name { get; set; }
public string Description { get; set; }
public ICollection<User> Users { get; set; }
} |
It is working with ci-12230. Note I am getting an error with the latest, ci-12237, Index out of range exception. |
Ok. Thanks for testing. Note that I have several branches running in parallel, that's the reason a later version can be a different/older branch. |
If I have something like
np(Element(@0).Value)
or
np(qList.FirstOrDefault(Tag = "NAME").Value)
I get a NullReferenceException in
ExpressionParser.GenerateConditional
in /Parser/ExpressionParser.cs line 1207.It works if I manually expand
np
to== null ? : null
- is there a limitation to whatnp
understands?The text was updated successfully, but these errors were encountered: