Grid.Blazor icon indicating copy to clipboard operation
Grid.Blazor copied to clipboard

DataAnnotation Null exception

Open borisdj opened this issue 4 years ago • 1 comments

Using info from Data_annotations I have tried to make Foo panel work but after click on menu 'Foo sample' we get an exception:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

that is thrown from line: var client = new GridClient<Foo>(q => fooService.GetFooGridRows(q), query, false, "fooGrid", null, locale); It seems to come from GridClient Constructor since all args are correct, fooService is loaded as well.

This is full stack:

This exception was originally thrown at this call stack:
    GridBlazor.CGrid<T>.ApplyGridSettings()
    GridBlazor.CGrid<T>.CGrid(System.Net.Http.HttpClient, string, System.Func<GridShared.Utility.QueryDictionary<Microsoft.Extensions.Primitives.StringValues>, GridShared.Utility.ItemsDTO<T>>, System.Func<GridShared.Utility.QueryDictionary<Microsoft.Extensions.Primitives.StringValues>, System.Threading.Tasks.Task<GridShared.Utility.ItemsDTO<T>>>, GridShared.Utility.IQueryDictionary<Microsoft.Extensions.Primitives.StringValues>, bool, System.Action<GridShared.IGridColumnCollection<T>>, System.Globalization.CultureInfo, GridShared.Columns.IColumnBuilder<T>)
    GridBlazor.CGrid<T>.CGrid(System.Func<GridShared.Utility.QueryDictionary<Microsoft.Extensions.Primitives.StringValues>, GridShared.Utility.ItemsDTO<T>>, GridShared.Utility.IQueryDictionary<Microsoft.Extensions.Primitives.StringValues>, bool, System.Action<GridShared.IGridColumnCollection<T>>, System.Globalization.CultureInfo, GridShared.Columns.IColumnBuilder<T>)
    GridBlazor.GridClient<T>.GridClient(System.Func<GridShared.Utility.QueryDictionary<Microsoft.Extensions.Primitives.StringValues>, GridShared.Utility.ItemsDTO<T>>, GridShared.Utility.QueryDictionary<Microsoft.Extensions.Primitives.StringValues>, bool, string, System.Action<GridShared.IGridColumnCollection<T>>, System.Globalization.CultureInfo, GridShared.Columns.IColumnBuilder<T>)
    BlazorGrid.Pages.FooSample.OnParametersSetAsync() in FooSample.razor
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

borisdj avatar Jun 22 '21 12:06 borisdj

I've loaded the Source and have managed to find the issue, null was thrown in CGrid.cs on line: Pager.PageSize = opt.PageSize; This happend because of attribute [GridTable(PagingEnabled = true, PageSize = 20)] And it seems that in CGrid constructor line Pager = new GridPager(query); is called after call to ApplyGridSettings(); So the fix is simple to move it before.

borisdj avatar Jun 22 '21 14:06 borisdj