Error in Browser Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

Hi,
i work on a Blazor Studio generated WASM hosted on IIS
with SQLServer DB.

The data is load via the generated 'OData-Pipeline' and
presented in a RadzenDataGrid. Works perfect and save me a lot of work.

Now i want to 'extend' the grid with additional columns that visualize data,
that relate on foreign keys; but there is no FK-Constraint in the DB.

A tip in this forum was the use of a Dictonary like:

public Dictionary<int, string> dM_Gruppe = new Dictionary<int, string>
{
{0, "fehlende Angabe" },
{1, "Großrisiken gem. § 210 VVG "},
{2, "Mittlere Kapitalgesellschaften "},
{3, "Kleine Kapitalgesellschaften"},
{4, "Verbraucher i.S. § 13 BGB"},
{5, "Kommunale Gebietskörperschaften"},
{6, "Insitutionen (Vereine, Verbände, Kirchen)"}
};

To use this Dictonary in several pages i create a service 'LookupService' with it inside.

My additional column was

@LookupService.dM_Gruppe[((tMandantens.Mandantengruppe.Equals(null)) ? 0 : tMandantens.Mandantengruppe.Value)]

The idea of this operator is: if there is a nullvalue in the column 'Mandantengruppe' then show "fehlende Angabe" in the cell!

If 'Mandantengruppe' is not null, the correct 'text' from the dictonary is shown, but if it is null, the browser throw an error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[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 MyAdmino.Client.Pages.TMandantens.<>c__DisplayClass48_3.b__13(RenderTreeBuilder __builder3) in G:\Projekte_Win_7\Radzen_BlazorStudio\MyAdmino_8 - Kopie_small - Net_7\Client\Pages\TMandantens.razor:line 56
at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
at Radzen.Blazor.RadzenDataGridRow1.<>c__DisplayClass0_1[[MyAdmino.Server.Models.MyAdminoDB.TMandanten, MyAdmino.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<BuildRenderTree>b__2(RenderTreeBuilder __builder2) at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment) at Radzen.Blazor.RadzenDataGridCell1[[MyAdmino.Server.Models.MyAdminoDB.TMandanten, MyAdmino.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b__0_2(RenderTreeBuilder __builder4)
at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
at Microsoft.AspNetCore.Components.CascadingValue1[[Radzen.Blazor.RadzenDataGridCell1[[MyAdmino.Server.Models.MyAdminoDB.TMandanten, MyAdmino.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Radzen.Blazor, Version=4.6.1.0, Culture=neutral, PublicKeyToken=null]].Render(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

Question: What is wrong with this expression:
@LookupService.dM_Gruppe[((tMandantens.Mandantengruppe.Equals(null)) ? 0 : tMandantens.Mandantengruppe.Value)]

Is there a better place where i can replace 'missing values' in a 'OData-result'?

thanks for help
Patric

Maybe a part of this expression is null - you can run the application using Visual Studio and check what's null using the debugger.

Hi Vladimir,
thanks for the fast reply;
I used VS2022 to debug and in the result set are some 'null' for tMandantens.Mandantengruppe. To make things even worse the type is short --> so cast to int.

But i try another expression with 'is' operator. And i don't no why, but this is working!!

@LookupService.dM_Gruppe[(tMandantens.Mandantengruppe is null) ? 0 : ((int) tMandantens.Mandantengruppe)]

This statement throws no errors in the browser and do the 'null'-replacement.

Thanks for help

Patric