Closed yallie closed 11 months ago
@yallie First, hi again.
Unable to get the service registration for the problematic FactoryID=20713656
Given the FactoryID is greater than 16 bit, it means that it is actually a decorator with upper 16 bits corresponding to the Decorated FactoryID. And it's need to be fixed to account for this situation.
You may try to use this code until it's fixed:
public static string TryGetDetails(IContainer container, ContainerException ex)
{
var e = ex.Error;
if (e == DryIoc.Error.WaitForScopedServiceIsCreatedTimeoutExpired)
{
var factoryId = (int)ex.Details;
// check `Request.CombineDecoratorWithDecoratedFactoryID()` for why is this logic
// var decoratorFactoryId = 0; // todo: @wip #598 add search for the `decoratorFactoryId`
if (factoryId > ushort.MaxValue)
{
// decoratorFactoryId = factoryId & ushort.MaxValue;
factoryId = factoryId >> 16;
}
foreach (var reg in container.GetServiceRegistrations())
{
var f = reg.Factory;
if (f.FactoryID == factoryId)
return $"The service registration related to the problem is:{Environment.NewLine}{reg}";
var genFactories = f.GeneratedFactories;
if (genFactories != null)
foreach (var genEntry in f.GeneratedFactories.Enumerate())
{
var generatedFactory = genEntry.Value;
if (generatedFactory.FactoryID == factoryId)
return $"The service registration related to the problem is:{Environment.NewLine}{reg}{Environment.NewLine}Specifically, its closed-generic factory is:{Environment.NewLine}{generatedFactory}";
}
}
return "Unable to find the service registration for the problematic factory with FactoryID={factoryId}";
}
return string.Empty;
}
Also, the message doesn't have the number of ticks it waited: for the ticks.
It was fixed in #475
Hi Maksim, thanks a lot for the explanation and the code sample! 🚀
Hello Maksim!
Is there a way to diagnose the WaitForScopedServiceIsCreatedTimeoutExpired error? I sometimes get an error message like this:
It happens when the app starts up and tries to execute a few scheduled tasks at once. The first task succeeds, and other tasks fail. But the next time they run — everything works fine. The issue doesn't reproduce every time the app starts up. Also, the message doesn't have the number of ticks it waited:
for the ticks
.Looks like the container reaches the timeout the first time it tries to resolve my services, but manages to create and cache a part of the dependency tree. And the second time, after a minute or so, everything works fine without any errors.
Calling
exception.TryGetDetails(container)
returns this:Is there an easy way to dump everything we know about this FactoryID at this point?
Cheers!
PS. It's DryIoc version 4.8.7, I'm going to update to the latest version as soon as I fix this issue.
PPS. Oops, I should have used Discussions tab, not Issues. My fault!