I’m getting an exception during app startup in my .NET Core 2.2 app. I added code for DI registration in Startup for the interface it is complaining about so I’m not sure how to fix this. I’ve tried placing the call for UseSentry()
before and after UseStartup<Startup>()
- neither work.
I’m using the pattern recommended in the Sentry docs: https://docs.sentry.io/platforms/dotnet/aspnetcore/#adding-event-and-exception-processors
System.InvalidOperationException: Cannot resolve 'System.Collections.Generic.IEnumerable`1[Sentry.Extensibility.ISentryEventExceptionProcessor]' from root provider because it requires scoped service 'Sentry.Extensibility.ISentryEventExceptionProcessor'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(Type serviceType, IServiceScope scope, IServiceScope rootScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceProviderEngineCallback.OnResolve(Type serviceType, IServiceScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.AspNetCore.Builder.ApplicationBuilderExtensions.UseSentry(IApplicationBuilder app) in C:\projects\sentry-dotnet\src\Sentry.AspNetCore\ApplicationBuilderExtensions.cs:line 49 at Sentry.AspNetCore.SentryStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder e) in C:\projects\sentry-dotnet\src\Sentry.AspNetCore\SentryStartupFilter.cs:line 15 at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Here is my code from Program.cs:
WebHost.CreateDefaultBuilder(args) .ConfigureLogging((hostingContext, logging) => { // Requires `using Microsoft.Extensions.Logging;` logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); logging.AddDebug(); logging.AddEventSourceLogger(); }) .UseStartup<Startup>() .UseSentry();
Startup code for DI:
// Sentry (logging/exception handling) services.AddTransient<ISentryEventProcessor, CustomEventProcessor>(); services.AddScoped<ISentryEventExceptionProcessor, CustomEventExceptionProcessor>();