An unhandled exception occurred while processing the request.

i am trying to add the ComponentSpace.Saml2 dll to the sample .net core project. but getting below error. Seems like DI issue. please help me resolving the issue.




InvalidOperationException: Unable to resolve service for type 'ComponentSpace.Saml2.ISamlIdentityProvider' while attempting to activate 'WebApplication6.Controllers.HomeController'.




You need to hook up the dependency injection.

For example:


// Add SAML SSO services.
builder.Services.AddSaml(builder.Configuration.GetSection(“SAML”));



The example projects demonstrate how to do this. You’ll also find information in the Developer and Examples Guides included with the product.

[quote]
ComponentSpace - 10/26/2023
You need to hook up the dependency injection.

For example:


// Add SAML SSO services.
builder.Services.AddSaml(builder.Configuration.GetSection("SAML"));



The example projects demonstrate how to do this. You'll also find information in the Developer and Examples Guides included with the product.
[/quote]

Its not working with this as well. What i am doing -
1. Created a .net core MVC project
2. Added the reference of ComponentSapce.saml2 dll(i did it using NuGet package manager)
https://www.nuget.org/packages/ComponentSpace.Saml2
3. Registed the service in programe.cs using below code

builder.Services.AddControllersWithViews();
builder.Services.AddSaml(builder.Configuration.GetSection("SAML"));

builder.Services.AddScoped();




An unhandled exception occurred while processing the request.

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.SignInManager[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'WebApplication7.Controllers.HomeController'.Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)






I’m not sure why you’re calling builder.Services.AddScoped<ISamlIdentityProvider, SamlIdentityProvider>(). Unless you’re implementing this interface yourself, don’t make this call. The call to builder.Services.AddSaml satisfies all the SAML dependencies.

It seems now your issue is with Microsoft.AspNetCore.Identity.SignInManager.

I highly recommend taking a look at the ExampleIdentityProvider project. This demonstrates calling the SAML API when acting as an identity provider as well as making use of Microsoft Identity including the SignInManager class. It’s built on the standard Visual Studio with the authentication type set to individual accounts.

Looking at the section of Program.cs you shared, you haven’t setup Microsoft Identity by calling builder.Services.AddDefaultIdentity etc. Perhaps you should create a new project but this time specify the authentication type as individual accounts.