System.Linq.Dynamic.Core: Blazor WASM NullReferenceException

1. Description

When attempting to run a simple query on a collection in Blazor, getting a NullReferenceException. The exact same query, on the exact same dataset, works perfectly in the Unit Tests, however when running in the browser you get the error image

2. Exception

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Arg_NullReferenceException
System.NullReferenceException: Arg_NullReferenceException
at System.Linq.Dynamic.Core.Parser.KeywordsHelper..ctor(ParsingConfig config)
at System.Linq.Dynamic.Core.Parser.ExpressionParser..ctor(ParameterExpression[] parameters, String expression, Object[] values, ParsingConfig parsingConfig)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values)
at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Any(IQueryable source, ParsingConfig config, String predicate, Object[] args)
at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Any(IQueryable source, String predicate, Object[] args)

See attachments for data sets, and try the following code:

[Fact]
public async Task Should_Work_With_Real_World_Values()
{
    // Arrange
    var formData = await File.ReadAllTextAsync("FormElement/form_data.json");
    var formElementData = await File.ReadAllTextAsync("FormElement/form_elements.json");
    var dataContext = JsonConvert.DeserializeObject<Dictionary<string, FormValue<string>>>(formData);
    var formElements = JsonConvert.DeserializeObject<FormElementReadModel[]>(formElementData);
    
    // Act
    var groupedElements = formElements
        .Where(element => element.Page == 2)
        .Where(element => dataContext.Values.AsQueryable()
            .Any(string.IsNullOrEmpty(element.InclusionRule) ? "true == true" : element.InclusionRule))
        .GroupBy(element => element.Group)
        .Select(group => new GroupedFormElements
        {
            Legend = group.Key ?? string.Empty,
            Elements = group.ToArray()
        }).ToArray();
    
    // Assert
    groupedElements.Any().ShouldBeTrue();
}

I’ve even tried the following code to take any of the dynamic elements out of the equation:

_groupedFormElements = _form.Elements
        .Where(element => element.Page == CurrentPage)
        .Where(element => _dataContext.Values.AsQueryable().Any("true == true"))
        .GroupBy(element => element.Group)
        .Select(group => new GroupedFormElements
        {
            Legend = group.Key ?? string.Empty,
            Elements = group.ToArray()
        }).ToArray();

but the same error persists.

As I say, only in Blazor. I have followed the documentation and do have image in the .csproj file

Any help would be gratefully appreciated

form_elements.zip

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15

Most upvoted comments

@jameswoodley i’m experiencing this problem, how did you fix this?