SyncfusionService not found in RCL (Razor Component Library), but registered in main project

Using server side Blazor.   As documented, I have added to ConfigureServices(..):
     services.AddSyncfusionBlazor();

I have a blazor component DLL that is referenced in my project but if I load the component, I get this:

Cannot provide a value for property 'SyncfusionService' on type 'Syncfusion.Blazor.RichTextEditor.SfRichTextEditor'. There is no registered service of type 'Syncfusion.Blazor.SyncfusionBlazorService'.

Is there any example of how to use SyncfusionService inside an RCL?
...or...
Is there a manual way to inject the service into my razor component page (e.g., Index.razor)?

5 Replies

IS Indrajith Srinivasan Syncfusion Team April 15, 2020 08:13 AM UTC

Hi Brian,

Greetings from Syncfusion support,

We have validated the reported query. we suggest you to refer the service in the Startup.cs file to resolve the exception from your end. Refer to the below reference link.

Documentation: https://blazor.syncfusion.com/documentation/common/how-to/troubleshoot/#runtime-exceptions

Please let us know if the solution helps,

Regards,
 
Indrajith 



BR BrianPD April 15, 2020 09:09 AM UTC

As I indicated, the Startup.cs file is already running AddSyncfusionBlazor()

The problem is

1) a component DLL does not have a startup.cs and thus no way to run the method AddSyncfusionBlazor()
2) Somehow the SyncfusionBlazor service is not being recognized by component DLLs.   I tried adding the component via nuget and it works for me that way.  But then I cannot dynamically add DLLs to my web application at runtime.

Is there a way to register the SyncfusionBlazor service a different way into the RCL?  Or maybe you have a different solution?

Thanks


JA Jesus Arockia Sankaran S Syncfusion Team April 20, 2020 12:41 PM UTC

Hi BrianPD, 

Sorry for not getting back to you sooner. 

We have looked into your reported query and we would suggest you to register the Syncfusion Blazor service by providing some helper services from your Razor Class Library (RCL) to achieve this requirement. Please refer to the below code example for more details. 

Sample reference: 

SyncfusionServices.cs (TestRazorLibrary) 

using Microsoft.Extensions.DependencyInjection; 
using System; 
using System.Collections.Generic; 
using System.Text; 
using Syncfusion.Blazor; 

namespace TestRazorLibrary.Helpers 
    public static class SyncfusionServices 
    { 
        public static IServiceCollection AddSyncfusionServices(this IServiceCollection services, bool DisableStaticAssetLoading = false) 
        { 
            if (services == null) 
            { 
                throw new ArgumentNullException(nameof(services)); 
            } 

            services.AddSyncfusionBlazor(DisableStaticAssetLoading); 

            return services; 
        } 

    } 


Startup.cs (SyncBlazorApp) 

//... 
using TestRazorLibrary.Helpers; 

namespace SyncBlazorApp 
    public class Startup 
    { 
        public Startup(IConfiguration configuration) 
        { 
            Configuration = configuration; 
        } 

        public IConfiguration Configuration { get; } 

        // This method gets called by the runtime. Use this method to add services to the container. 
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 
        public void ConfigureServices(IServiceCollection services) 
        { 
            //... 
            services.AddSyncfusionServices(); 
        } 

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 
        { 
           //... 
        } 
    } 


Could you please check the above sample and get back to us if we misunderstood your requirement or you need further assistance on this? 
 
Regards, 
Jesus Arockia Sankaran S 



TO Toine March 7, 2021 02:40 AM UTC

I'm receiving a similar error with Blazor Webassemby.
This solution doesn't work since Blazor Webassemby has no Startup.cs, what should I do.

Cannot provide a value for property 'SyncfusionService' on type 'Syncfusion.Blazor.Buttons.SfRadioButton`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. There is no registered service of type 'Syncfusion.Blazor.SyncfusionBlazorService'.
System.InvalidOperationException: Cannot provide a value for property 'SyncfusionService' on type 'Syncfusion.Blazor.Buttons.SfRadioButton`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. There is no registered service of type 'Syncfusion.Blazor.SyncfusionBlazorService'.


MK Muthukumar Kannan Syncfusion Team March 8, 2021 03:35 PM UTC

Hi Toine, 

Thanks for your update. 

Based on your provided information, we would like to suggest you register the service in the ‘program.cs’ for WebAssembly application. Please refer to the below snippets for more details. 

program.cs 

using System.Collections.Generic; 
using System.Threading.Tasks; 
using System.Text; 
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 
using Microsoft.Extensions.Configuration; 
using Microsoft.Extensions.DependencyInjection; 
using Microsoft.Extensions.Logging; 
using TestRazorLibrary.Helpers; 
 
namespace BlazorWasmApp 
{ 
    public class Program 
    { 
        public static async Task Main(string[] args) 
        { 
            var builder = WebAssemblyHostBuilder.CreateDefault(args); 
            builder.RootComponents.Add<App>("app"); 
 
            builder.Services.AddSyncfusionServices(); 
 
           builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 
 
            await builder.Build().RunAsync(); 
        } 
    } 
} 

Also, we have prepared a similar sample in WebAssembly for your convenience and the same can be downloaded from the link below. 

Sample: 

Please check with the above-suggested solution and get back to us if you have any queries or need further assistance. 

Regards, 
Muthukumar K 


Loader.
Up arrow icon