Cannot provide a value for property 'DialogService' Error

Application works fine in Visual Studio however I'm getting below errors on Radzen Blazor Studio.

Already added services on Program.cs

    builder.Services.AddScoped<DialogService>();
    builder.Services.AddScoped<NotificationService>();

Here is the error log;

System.InvalidOperationException: Cannot provide a value for property 'DialogService' on type 'LumosR.Pages.AddAssignment'. There is no registered service of type 'Radzen.DialogService'.
   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)

Can you show us the complete code of Program.cs?

Sure;

using LumosR.Pages;
using LumosR.Shared;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Radzen;
using Serilog;
using Serilog.Events;
using System.Reflection;


Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information).WriteTo.File(@"Logs\Info.log", rollingInterval: RollingInterval.Day))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug).WriteTo.File(@"Logs\Debug.log", rollingInterval: RollingInterval.Day))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning).WriteTo.File(@"Logs\Warning.log", rollingInterval: RollingInterval.Day))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error).WriteTo.File(@"Logs\Error.log", rollingInterval: RollingInterval.Day))
.WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal).WriteTo.File(@"Logs\Fatal.log", rollingInterval: RollingInterval.Day))
.WriteTo.File(@"Logs\Verbose.log", rollingInterval: RollingInterval.Day)
.CreateLogger();

try
{
    Log.Information("STARTING LUMOS..");

    var builder = WebApplication.CreateBuilder(args);

    builder.Services.AddRazorPages();
    builder.Services.AddServerSideBlazor().AddHubOptions(o =>
    {
        o.MaximumReceiveMessageSize = 10 * 1024 * 1024;
    });
    builder.Services.AddScoped<DialogService>();
    builder.Services.AddScoped<NotificationService>();
    builder.Services.AddScoped<TooltipService>();
    builder.Services.AddScoped<ContextMenuService>();
    builder.Services.AddScoped<AddCredential>();
    builder.Services.AddLocalization();
    builder.Host.UseSerilog();

    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        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.UseStaticFiles();
    app.UseRouting();
    app.MapControllers();
    app.MapBlazorHub();
    app.MapFallbackToPage("/_Host");

    app.Run();
}
catch (Exception ex)
{
    Log.Fatal(ex, "Application terminated unexpectedly");
}
finally
{
    Log.CloseAndFlush();
}

I think the try/catch block is causing this problem.

1 Like

I'm getting the same peculiar error when using the Radzen Design View through Radzen Blazor Studio for Visual Studio or through Radzen Blazor Studio IDE. I moved all the builder services to a ServiceCollectionBuilder extension class and the subsequent App Middleware configurations to an ApplicationBuilderExtension class. Even though the Build appears to be complete usually, I cannot use the Design-Time Render Layout in either Visual Studio 2022 IDE or Radzen Blazor Studio IDE. Do you have any ideas as to what could be the problem?

I am attaching my zipped Source Code:VisionSuiteShipManagerServer Source

Curren

This is probably what is causing the problem however I can't test your app due to this error:

error CS0246: The type or namespace name 'ProductBarcodeValidator' could not be found (are you missing a using directive or an assembly reference?)

You can try calling builder.Services.AddRadzenComponents() in Program.cs within a preprocessor directive:

#if RADZEN
builder.Services.AddRadzenComponents();
#endif

I added the ProductBarcodeValidatorProject to the project, and I did what you recommended with no change. Also, the builder.Services.AddRadzenComponents(); statement is already in the ServiceCollectionBuilderExtensions.cs. Should I remove it from the extension and place it directly in the Program.cs, or should I add each component individually as a scoped service?

VisionSuiteShipManagerServer_Archive_20250109-1.zip

Well that's what I suggested:

I think that you misunderstand. I added the
#if RADZEN
builder.Services.AddRadzenComponents();
#endif
as you suggested, and there was no change. It still generated the same error.

Page Cannor be Rendered:

System.InvalidOperationException: Cannot provide a value for property 'DialogService' on type 'VisionSuiteShipManagerServer.Components.Layout.MainLayout'. There is no registered service of type 'Radzen.DialogService'.
at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass9_0.g__Initialize|1(IServiceProvider serviceProvider, IComponent component)
at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable1 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, ArrayRange1 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)

Can you confirm that you have it in Program.cs? I don't see it in the updated project.

I placed it after the AddApplication Services call in the Program.cs file.


Log.Information("Starting web application");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container
Log.Information("Adding Application Services to the container");   
await builder.Services.AddApplicationServices(builder.Configuration, builder.Environment).ConfigureAwait(false);

#if RADZEN
builder.Services.AddRadzenComponents();
#endif

Log.Information("Building the API");
var app = builder.Build();

I am also attaching a new Zipped Code File:
VisionSuiteShipManagerServer_Archive_20250109-2.zip

I can't open the updated solution. It refers to a project I don't have:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductBarcodeValidator", "..\..\..\Libraries\Generic\ProductBarcodeValidator\ProductBarcodeValidator\ProductBarcodeValidator.csproj", "{4EBD590A-1B4F-48F6-8ED2-01B5E544CE54}"
EndProject
G

I also checked the updated Program.cs - it still doesn't include the requested change:

using System.IdentityModel.Tokens.Jwt;
using Brickmakers.AspSecurityHeaders;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.OData;
using Microsoft.EntityFrameworkCore;
using Microsoft.OData.ModelBuilder;
using Radzen;
using Serilog;
using VisionSuiteShipManagerServer.Components;
using VisionSuiteShipManagerServer.Data;
using VisionSuiteShipManagerServer.Exceptions;
using VisionSuiteShipManagerServer.Extensions;
using VisionSuiteShipManagerServer.Models;
using VisionSuiteShipManagerServer.Services;


// Setup Serilog for logging
var configuration = new ConfigurationBuilder().BuildConfiguration();
Log.Logger = await configuration.CreateBootstrapLoggerAsync().ConfigureAwait(false);

try
{
    Log.Information("Starting web application");
    var builder = WebApplication.CreateBuilder(args);

    // Add services to the container
    Log.Information("Adding Application Services to the container");   
    await builder.Services.AddApplicationServices(builder.Configuration, builder.Environment).ConfigureAwait(false);

    Log.Information("Building the API");
    var app = builder.Build();

    // Configure the HTTP request pipeline
    Log.Information("Configuring the HTTP request pipeline");
    await app.ConfigureMiddlewareAsync().ConfigureAwait(false);

    // Ensures that the Database Associated with ApplicationIdentityDbContext is Created Asynchronously,
    // if it does not already exist.
    Log.Information(" => Processing Application Database Context Create (if not exist) Asynchronously");
    await app.Services.CreateScope()
        .ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>()
        .Database.EnsureCreatedAsync()
        .ConfigureAwait(false);

    // Ensures that the Database Schema Associated with ApplicationIdentityDbContext is Migrated Asynchronously,
    // if it does not already exist.
    Log.Information(" => Processing Application Database Schema Migrate (if not exist) Asynchronously");
    await app.Services.CreateScope()
        .ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>()
        .Database.MigrateAsync()
        .ConfigureAwait(false);

    Log.Information("Running the Application");
    GlobalDataService.ApplicationStartDate = DateTime.Now;
    await app.RunAsync().ConfigureAwait(false);
    //app.Run();

    Log.Information("Stopped cleanly");
    return 0;
}
catch (Exception ex)
{
    Log.Fatal(ex, "An unhandled exception occurred during bootstrapping");
    return 1;
}
finally
{
    Log.CloseAndFlush();
}

I am afraid I can't do much to help in this situation.

Here is the zipped source again. And I verified that it's in there.
VisionSuiteShipManagerServer_Archive_20250110.zip
By the way, how do I validate that the RADZEN Variable is Set?

using System.IdentityModel.Tokens.Jwt;
using Brickmakers.AspSecurityHeaders;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.OData;
using Microsoft.EntityFrameworkCore;
using Microsoft.OData.ModelBuilder;
using Radzen;
using Serilog;
using VisionSuiteShipManagerServer.Components;
using VisionSuiteShipManagerServer.Data;
using VisionSuiteShipManagerServer.Exceptions;
using VisionSuiteShipManagerServer.Extensions;
using VisionSuiteShipManagerServer.Models;
using VisionSuiteShipManagerServer.Services;

// Setup Serilog for logging
var configuration = new ConfigurationBuilder().BuildConfiguration();
Log.Logger = await configuration.CreateBootstrapLoggerAsync().ConfigureAwait(false);

try
{
Log.Information("Starting web application");
var builder = WebApplication.CreateBuilder(args);

// Add services to the container
Log.Information("Adding Application Services to the container");   
await builder.Services.AddApplicationServices(builder.Configuration, builder.Environment).ConfigureAwait(false);

//*****************************************************************************************************************
// WPE (20250110) - Add the following to the Add the Radzen Components in the Program.cs file Just in Case
// It's Missed I Guess
//*****************************************************************************************************************

#if RADZEN
Log.Information(" => Re-Adding Radzen Components");
builder.Services.AddRadzenComponents();
builder.Services.AddRadzenCookieThemeService(options =>
{
options.Name = "VisionSuiteShipManagerServerTheme";
options.Duration = TimeSpan.FromDays(365);
});
#endif
//*****************************************************************************************************************

Log.Information("Building the API");
var app = builder.Build();

// Configure the HTTP request pipeline
Log.Information("Configuring the HTTP request pipeline");
await app.ConfigureMiddlewareAsync().ConfigureAwait(false);

// Ensures that the Database Associated with ApplicationIdentityDbContext is Created Asynchronously,
// if it does not already exist.
Log.Information(" => Processing Application Database Context Create (if not exist) Asynchronously");
await app.Services.CreateScope()
    .ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>()
    .Database.EnsureCreatedAsync()
    .ConfigureAwait(false);

// Ensures that the Database Schema Associated with ApplicationIdentityDbContext is Migrated Asynchronously,
// if it does not already exist.
Log.Information(" => Processing Application Database Schema Migrate (if not exist) Asynchronously");
await app.Services.CreateScope()
    .ServiceProvider.GetRequiredService<ApplicationIdentityDbContext>()
    .Database.MigrateAsync()
    .ConfigureAwait(false);

Log.Information("Running the Application");
GlobalDataService.ApplicationStartDate = DateTime.Now;
await app.RunAsync().ConfigureAwait(false);
//app.Run();

Log.Information("Stopped cleanly");
return 0;

}
catch (Exception ex)
{
Log.Fatal(ex, "An unhandled exception occurred during bootstrapping");
return 1;
}
finally
{
Log.CloseAndFlush();
}

I added code to the Program.cs file that verifys whether ALL Registered Services when the Web Application Loads and ALL Radzen Components are loaded correctly. Additionally, I am attaching the Radzen Analysis Log and a Screenshot of the transient error message that I saw during the Index.razor / Index.razor.cs Design-Time Build before the build failure.

VisionSuiteShipManagerServer_Archive_20250112-6.zip

VisionSuiteShipManagerServer_Verify.log

RazorPageCompileError_Screenshot 2025-01-12 164058.png

The latest zip file again uses a project which is not included. I cannot test it.

The problem is the same which I have reported earlier.

By the way the code I have requested you to add is commented in Program.cs. It won't run during design-time builds.

try
{
    Log.Information("Starting web application");
    var builder = WebApplication.CreateBuilder(args);

    // Add services to the container
    Log.Information("Adding Application Services to the container");
    await builder.Services.AddApplicationServices(builder.Configuration, builder.Environment).ConfigureAwait(false);

    //*****************************************************************************************************************
    // WPE (20250110) - Add the following to the Add the Radzen Components in the Program.cs file Just in Case
    // It's Missed I Guess
    //*****************************************************************************************************************
    //#if RADZEN
    //        Log.Information(" => Re-Adding Radzen Components");
    //        builder.Services.AddRadzenComponents();
    //        builder.Services.AddRadzenCookieThemeService(options =>
    //        {
    //            options.Name = "VisionSuiteShipManagerServerTheme";
    //            options.Duration = TimeSpan.FromDays(365);
    //        });
    //#endif

Finally I am positive your project used to work quite well in design time when I tested an earlier version of it (one that didn't start the browser because you have stopped logging to the terminal). I suggest using source control to find which change made this design-time error to start appearing.

I guess I will have to build a special application for you without the ProductBarcodeValidator project because it is a referenced project that I can't set up for you. I also noticed a bug in the Authorization Controller that has to do with multiple users that have TwoFactorEnabled set as true and false per user. In other words, you cannot have 2 or more users having different boolean settings for the TwoFactorEnabled column. It's either all or nothing as it conflicts with the TwoFactorRequired state. So it will be a day.