Last time I managed to catch it, it was trying to resolve Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector, which is a singleton. Sure enough, it was trying to store an instance, when there was already one in the collection.
I am wondering how this could have possibly occurred.
Just a hypothesis, but could this be a threading issue where one thread is instantiating and storing the singleton instance whilst another attempts to resolve it and by the time it attempts to store it, the first thread has already stored an instance and so you get the duplicate key? Perhaps there is some locking elsewhere that stops such a thing happening?
I will continue to try and reproduce this reliably in the meantime but I thought I would report it.
I am getting an intermittent error that I am still trying to pin down occurring at: https://github.com/JasperFx/lamar/blob/2693d503b560283950119bbae12987b3da877342/src/Lamar/IoC/Instances/Instance.cs#L221
Last time I managed to catch it, it was trying to resolve
Microsoft.AspNetCore.Mvc.Infrastructure.DefaultOutputFormatterSelector
, which is a singleton. Sure enough, it was trying to store an instance, when there was already one in the collection.Looking up the stack, at:
https://github.com/JasperFx/lamar/blob/2693d503b560283950119bbae12987b3da877342/src/Lamar/IoC/Instances/ConstructorInstance.cs#L123
I am wondering how this could have possibly occurred.
Just a hypothesis, but could this be a threading issue where one thread is instantiating and storing the singleton instance whilst another attempts to resolve it and by the time it attempts to store it, the first thread has already stored an instance and so you get the duplicate key? Perhaps there is some locking elsewhere that stops such a thing happening?
I will continue to try and reproduce this reliably in the meantime but I thought I would report it.