Skip to content
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

Closed
NetMage opened this issue Sep 7, 2019 · 15 comments
Closed

np (NullPropagation) throws NullReferenceException with methods #302

NetMage opened this issue Sep 7, 2019 · 15 comments
Labels

Comments

@NetMage
Copy link

NetMage commented Sep 7, 2019

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 what np understands?

@StefH
Copy link
Collaborator

StefH commented Sep 7, 2019

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...

@StefH StefH added the question label Sep 7, 2019
@StefH StefH changed the title np NulLReferenceException with methods np NullReferenceException with methods Sep 7, 2019
@StefH StefH changed the title np NullReferenceException with methods np (NullPropagation) throws NullReferenceException with methods Sep 7, 2019
@StefH
Copy link
Collaborator

StefH commented Sep 7, 2019

@NetMage

Please try MyGet preview version : System.Linq.Dynamic.Core.1.0.19-ci-11874

@NetMage
Copy link
Author

NetMage commented Sep 20, 2019

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.

@StefH
Copy link
Collaborator

StefH commented Sep 20, 2019

Did you try that exact version?

@StefH StefH added bug and removed question labels Sep 21, 2019
@StefH
Copy link
Collaborator

StefH commented Sep 21, 2019

@StefH
Copy link
Collaborator

StefH commented Oct 10, 2019

@NetMage Did you have time to test?

@StefH
Copy link
Collaborator

StefH commented Oct 29, 2019

@NetMage Can you please verify ?

@StefH
Copy link
Collaborator

StefH commented Nov 13, 2019

@NetMage can you please test if this version does fix your issue?

@NetMage
Copy link
Author

NetMage commented Nov 22, 2019

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?

@StefH
Copy link
Collaborator

StefH commented Nov 23, 2019

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.

@NetMage
Copy link
Author

NetMage commented Nov 25, 2019

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 Select:

    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; }
    }

@StefH
Copy link
Collaborator

StefH commented Nov 26, 2019

Please try version System.Linq.Dynamic.Core.1.0.20-ci-12230, that one works for me:

image

@NetMage
Copy link
Author

NetMage commented Nov 26, 2019

It is working with ci-12230. Note I am getting an error with the latest, ci-12237, Index out of range exception.

@StefH
Copy link
Collaborator

StefH commented Nov 26, 2019

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.

@StefH
Copy link
Collaborator

StefH commented Nov 26, 2019

#309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants