-
Notifications
You must be signed in to change notification settings - Fork 357
Description
Expected Behavior
IServiceCollection.BuildServiceProvider() should never ever be called from application code because it can result in more than one copy of singleton services being created.
Actual Behavior
Adding AddDaprWorkflow call while using Serilog bootstrap logger will throw exception because singleton logger gets created twice:
System.InvalidOperationException: The logger is already frozen.
at Serilog.Extensions.Hosting.ReloadableLogger.Freeze()
at Serilog.SerilogServiceCollectionExtensions.<>c__DisplayClass3_0.b__0(IServiceProvider services)
Freeze method is called only in singleton factory method.
Thrown exception suggests singleton factory method has been called twice.
This is just one symptom that I ran into, but this can cause other issues depending on what singletons an application is using.
Steps to Reproduce the Problem
- Create new ASP.NET Core Web API project
- Add Serilog nugets
- Add Dapr.Workflow nuget
- In Program.Main create bootstrap logger
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger(); - Add dapr workflows: builder.Services.AddDaprWorkflow(x => { });
- Run the app and observe InvalidOperationException being thrown preventing startup
Root cause can be found here.
Call to BuildServiceProvider() produces warning that someone choose to ignore.
Release Note
RELEASE NOTE: