DataGrid: Exception when using AddSingleton approach in shell app
Null reference exception when using the AddSingleton approach in the shell app.
1 comment
ADMIN
Lance | Senior Manager Technical Support
Posted on:18 May 2023 13:33
Hi Community,
If you've landed on this item, you can resolve the issue by using AddScoped (instead of AddSingleton or AddTransient).
For example:
publicstatic MauiAppBuilder RegisterViews(this MauiAppBuilder mauiAppBuilder)
{
// These may try to instantiate objects in the XAML too soon, before MauiApplication.Current is available// mauiAppBuilder.Services.AddSingleton<MyDataGridPage>();// mauiAppBuilder.Services.AddTransient<MyDataGridPage>();// Solution
mauiAppBuilder.Services.AddScoped<MyDataGridPage>();
return mauiAppBuilder;
}
Regards,
Lance | Manager Technical Support
Progress Telerik