Master/Detail Hierarchy datagrid error when expanding empty master record

I am using Radzen 2.46.5 release.
I created a new Blazor Radzen project based on sample Northwind SQL Server database and used the Master Detail Hierarchy page wizard with Order as master and orderDetails
When I add a new order record and try to expand it to be able to create order details records, I get the following runtime error in the Chrome browser:
blazor.server.js:15 [2020-04-26T15:34:56.078Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
at Test1.Pages.OrderComponent.Grid0RowExpand(Order args) in C:\Radzen\Test1\server\Pages\Order.razor.designer.cs:line 102
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Radzen.Blazor.RadzenGrid`1.ExpandItem(TItem item)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

The Radzen output window also shows the following error:

dotnet: info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[Freight], [o0].[OrderDate], [o0].[RequiredDate], [o0].[ShipAddress], [o0].[ShipCity], [o0].[ShipCountry], [o0].[ShipName], [o0].[ShipPostalCode], [o0].[ShipRegion], [o0].[ShipVia], [o0].[ShippedDate], [p].[ProductID], [p].[CategoryID], [p].[Discontinued], [p].[ProductName], [p].[QuantityPerUnit], [p].[ReorderLevel], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock], [p].[UnitsOnOrder]
FROM [dbo].[Order Details] AS [o]
INNER JOIN [dbo].[Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID]
INNER JOIN [dbo].[Products] AS [p] ON [o].[ProductID] = [p].[ProductID]
WHERE [o].[OrderID] = 11078

dotnet: warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Test1.Pages.OrderComponent.Grid0RowExpand(Order args) in C:\Radzen\Test1\server\Pages\Order.razor.designer.cs:line 102
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Radzen.Blazor.RadzenGrid`1.ExpandItem(TItem item)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

dotnet: fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'UFrs0QxYjR6g4JpGeU7IY207IfoNLV0Jpqg_reW00TU'.
System.NullReferenceException: Object reference not set to an instance of an object.
at Test1.Pages.OrderComponent.Grid0RowExpand(Order args) in C:\Radzen\Test1\server\Pages\Order.razor.designer.cs:line 102
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Radzen.Blazor.RadzenGrid`1.ExpandItem(TItem item)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

dotnet: info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint '/_blazor'

dotnet: info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 12584.9173ms 101

Can you run your project with Visual Studio and check what is null?

I upgraded to Radzen 2.4.6 today and I am using Visual Studio Community 2019 version 16.5.4.
The error occurs in Radzen as well as Visual Studio. Screen capture attached.

When running in Visual Studio, I get an execution at the following line

if(nwGetOrderDetailsResult != null){nwGetOrderDetailsResult.ToList().ForEach(args.OrderDetails.Add);};

The exception details follow:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Test1
StackTrace:
at Test1.Pages.OrderComponent.d__38.MoveNext() in C:\Radzen\Test1\server\Pages\Order.razor.designer.cs:line 102

The output window in Visual Studio displays the following debuging information:

Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:5000/assets/css/styles.css
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:5000/_content/Radzen.Blazor/css/default.css
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:5000/assets/css/styles-generated.css
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Information: The file /assets/css/styles.css was not modified
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Information: The file /_content/Radzen.Blazor/css/default.css was not modified
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 13.3147ms 304 text/css
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Information: The file /assets/css/styles-generated.css was not modified
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 12.6976ms 304 text/css
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 16.9557ms 304 text/css
Microsoft.EntityFrameworkCore.Database.Command: Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*)
FROM [dbo].[Orders] AS [o]
Microsoft.EntityFrameworkCore.Database.Command: Information: Executed DbCommand (1ms) [Parameters=[@__p_0='?' (DbType = Int32), @__p_1='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[Freight], [t].[OrderDate], [t].[RequiredDate], [t].[ShipAddress], [t].[ShipCity], [t].[ShipCountry], [t].[ShipName], [t].[ShipPostalCode], [t].[ShipRegion], [t].[ShipVia], [t].[ShippedDate], [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [e].[EmployeeID], [e].[Address], [e].[BirthDate], [e].[City], [e].[Country], [e].[Extension], [e].[FirstName], [e].[HireDate], [e].[HomePhone], [e].[LastName], [e].[Notes], [e].[Photo], [e].[PhotoPath], [e].[PostalCode], [e].[Region], [e].[ReportsTo], [e].[Title], [e].[TitleOfCourtesy], [s].[ShipperID], [s].[CompanyName], [s].[Phone]
FROM (
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[Freight], [o].[OrderDate], [o].[RequiredDate], [o].[ShipAddress], [o].[ShipCity], [o].[ShipCountry], [o].[ShipName], [o].[ShipPostalCode], [o].[ShipRegion], [o].[ShipVia], [o].[ShippedDate]
FROM [dbo].[Orders] AS [o]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY
) AS [t]
LEFT JOIN [dbo].[Customers] AS [c] ON [t].[CustomerID] = [c].[CustomerID]
LEFT JOIN [dbo].[Employees] AS [e] ON [t].[EmployeeID] = [e].[EmployeeID]
LEFT JOIN [dbo].[Shippers] AS [s] ON [t].[ShipVia] = [s].[ShipperID]
The thread 0x46d8 has exited with code 0 (0x0).
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\System.Security.Cryptography.Encoding.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\System.Diagnostics.TraceSource.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\System.Security.AccessControl.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\System.ComponentModel.EventBasedAsync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.EntityFrameworkCore.Database.Command: Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice], [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[Freight], [o0].[OrderDate], [o0].[RequiredDate], [o0].[ShipAddress], [o0].[ShipCity], [o0].[ShipCountry], [o0].[ShipName], [o0].[ShipPostalCode], [o0].[ShipRegion], [o0].[ShipVia], [o0].[ShippedDate], [p].[ProductID], [p].[CategoryID], [p].[Discontinued], [p].[ProductName], [p].[QuantityPerUnit], [p].[ReorderLevel], [p].[SupplierID], [p].[UnitPrice], [p].[UnitsInStock], [p].[UnitsOnOrder]
FROM [dbo].[Order Details] AS [o]
INNER JOIN [dbo].[Orders] AS [o0] ON [o].[OrderID] = [o0].[OrderID]
INNER JOIN [dbo].[Products] AS [p] ON [o].[ProductID] = [p].[ProductID]
WHERE [o].[OrderID] = 11078
Exception thrown: 'System.NullReferenceException' in Test1.dll
Object reference not set to an instance of an object.

Please note that I get this error in any project that uses the Master/Detail Hierarchy page template no matter what project is used.
The generated code works fine as long as there are existing detail records.
Only when expanding a master record that doesn't have and detail records results with this exception/ error message.
If I refresh the page, I can continue using the application as long as I do not try to expand a master record that doesn't have any details.

Thanks! It will be fixed in the next update.

This is the same issue. Fix is use foreach instead of ForEach()

It is fixed already in our meta template. In the next version there will be no ForEach - just set with condition and ToList(). For example:

var someResult = ...
if(someResult != null) 
{
   args.SomeProperty = someResult.ToList();
}
1 Like

I just upgraded to Radzen 2.47.0 released on 2020-04-30 and the generated code resulting in the same error has not changed.
Looking forward to a near future update that fixes the error.

Radzen version 2.47.0 resolved the issue. Thanks to the Radzen team for their quick response snd fix.
You can delete the page that was generated from a prior version and Radzen 2.47.0 genetaes the correct code that works without an error.
If you do not want to delete the page, you can change the "Then" handler to remove the following section of the code:
.ForEach(event.OrderDetails.Ass)

In other words the code should be:
if(${result} != null) {${result}.ToList();}