Radzen Blazor Studio - "The page cannot render" Error Report

I am encountering a "The page cannot render" error while using Radzen Blazor Studio Design Page.

However, the program can be executed normally, and the page can be displayed normally during execution.

Error Message:

Cannot provide a value for property 'titan_builderService' on type 'Test.Client.Pages.TbBudrUsers'. There is no registered service of type 'Test.Client.titan_builderService'.
   at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass9_0.<CreatePropertyInjector>g__Initialize|1(IServiceProvider serviceProvider, IComponent component)
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable`1 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
   at Radzen.Server.RemoteRenderer.HandleException(Exception exception)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
   at Radzen.Server.Router.Render(Type layout, Type component, Boolean renderLayout)
   at Radzen.Server.Router.OnRouteChanged(Object sender, RouteChangedEventArgs e)
   at Radzen.Server.RouterService.Route(Type component, Type defaultLayout, Boolean renderLayout)
   at Radzen.Server.CircuitHost.AddComponent(Type layout, Type page, Boolean renderLayout)
   at Radzen.Server.ProjectServer.Render(String fileName, String source, Boolean renderLayout)
   at Radzen.Server.ProgramController.Render(RenderRequest request)

Context:

  • My data source is a 'psql' database configured through the "Data" menu.
  • The Razor page was generated using the CRUD template.
  • Authentication is implemented using Azure AD through the "Security" menu.

Code Snippets:

For your reference, I have included the following code snippets:

  1. **Client.Program.cs:
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Radzen;
using Test.Client;
using Microsoft.JSInterop;
using System.Globalization;
using Microsoft.AspNetCore.Components.Authorization;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.Services.AddRadzenComponents();
builder.Services.AddRadzenCookieThemeService(options =>
{
    options.Name = "TestTheme";
    options.Duration = TimeSpan.FromDays(365);
});
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddLocalization();
builder.Services.AddHttpClient("Test.Server", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress));
builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("Test.Server"));
builder.Services.AddScoped<Test.Client.SecurityService>();
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AuthenticationStateProvider, Test.Client.ApplicationAuthenticationStateProvider>();
builder.Services.AddScoped<titan_builderService>();
var host = builder.Build();
var jsRuntime = host.Services.GetRequiredService<Microsoft.JSInterop.IJSRuntime>();
var culture = await jsRuntime.InvokeAsync<string>("Radzen.getCulture");
if (!string.IsNullOrEmpty(culture))
{
    CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
    CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(culture);
}

await host.RunAsync();
  1. **Server.Program.cs:
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Radzen;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Identity.Web;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.OData.ModelBuilder;
using Microsoft.AspNetCore.OData;

var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddRadzenComponents();
builder.Services.AddRadzenCookieThemeService(options =>
{
    options.Name = "TestTheme";
    options.Duration = TimeSpan.FromDays(365);
});
builder.Services.AddSingleton(sp =>
{
    // Get the address that the app is currently running at
    var server = sp.GetRequiredService<IServer>();
    var addressFeature = server.Features.Get<IServerAddressesFeature>();
    string baseAddress = addressFeature.Addresses.First();
    return new HttpClient
    {
        BaseAddress = new Uri(baseAddress)
    };
});
builder.Services.AddLocalization();
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme).AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddAuthorization();
builder.Services.AddHttpClient("Test.Server").AddHeaderPropagation(o => o.Headers.Add("Cookie"));
builder.Services.AddHeaderPropagation(o => o.Headers.Add("Cookie"));
builder.Services.AddScoped<AuthenticationStateProvider, Test.Client.ApplicationAuthenticationStateProvider>();
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<Test.Client.SecurityService>();
builder.Services.AddScoped<Test.Server.titan_builderService>();
builder.Services.AddScoped<Test.Client.titan_builderService>();
builder.Services.AddDbContext<Test.Server.Data.titan_builderContext>(options =>
{
    options.UseNpgsql(builder.Configuration.GetConnectionString("titan_builderConnection"));
});
builder.Services.AddControllers().AddOData(opt =>
{
    var oDataBuildertitan_builder = new ODataConventionModelBuilder();
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbAppSetting>("TbAppSettings");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrGroup>("TbBudrGroups");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrRewardMonth>("TbBudrRewardMonths");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrRewardType>("TbBudrRewardTypes");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrUser>("TbBudrUsers");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrUserGroup>("TbBudrUserGroups");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbBudrUserReward>("TbBudrUserRewards");
    oDataBuildertitan_builder.EntitySet<Test.Server.Models.titan_builder.TbTemplate>("TbTemplates");
    opt.AddRouteComponents("odata/titan_builder", oDataBuildertitan_builder.GetEdmModel()).Count().Filter().OrderBy().Expand().Select().SetMaxTop(null).TimeZone = TimeZoneInfo.Utc;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseHeaderPropagation();
app.UseStaticFiles();
app.UseRequestLocalization(options => options.AddSupportedCultures("en", "zh-CHS").AddSupportedUICultures("en", "zh-CHS").SetDefaultCulture("en"));
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.MapControllers();
app.MapFallbackToPage("/_Host");
app.Run();

Could you please assist me in resolving this issue?

Thank you for your time and support.

Sincerely,

Aron

I tried to remove @attribute [Authorize] from the razor page, but the error still occurred. Then I changed
in the razor.cs page

 [Inject]
 public titan_builderService titan_builderService { get; set; }

Change to

#if !RADZEN
        [Inject]
#endif
        public titan_builderService titan_builderService { get; set; }

The page can be displayed normally
in conclusion:

  1. Remove @attribute [Authorize]
  2. Change the
    [Inject]
    to
    #if !RADZEN
                [Inject]
    #endif
    

annotation of titan_builderService