Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsRegistered throws IndexOutOfRangeException for open generic type. #1040

Closed
hypercodeplace opened this issue Oct 30, 2019 · 2 comments
Closed

Comments

@hypercodeplace
Copy link

Assembly version: 4.9.4.0

[Test]
public void IsRegisteredTest()
{
    void Test(Type typeFrom, Type typeTo)
    {
        var containerBuilder = new ContainerBuilder();
        containerBuilder.RegisterGeneric(typeTo).As(typeFrom);

        var container = containerBuilder.Build();

        Assert.IsFalse(container.IsRegistered(typeFrom));
    }

    Test(typeof(IFoo<>), typeof(Foo<>)); // Passed
    Test(typeof(Foo<>), typeof(Foo<>));  // Failed with "IndexOutOfRangeException".
}

public interface IFoo<T> { }
public class Foo<T> : IFoo<T> { }

The stack trace:

System.IndexOutOfRangeException : Index was outside the bounds of the array.
   at Autofac.Util.TypeExtensions.IsCompatibleWithGenericParameterConstraints(Type genericTypeDefinition, Type[] parameters)
   at Autofac.Features.OpenGenerics.OpenGenericServiceBinder.TryBindServiceType(Service service, IEnumerable`1 configuredOpenGenericServices, Type openGenericImplementationType, Type& constructedImplementationType, Service[]& constructedServices)
   at Autofac.Features.OpenGenerics.OpenGenericRegistrationSource.RegistrationsFor(Service service, Func`2 registrationAccessor)+MoveNext()
   at Autofac.Core.Registration.ComponentRegistry.GetInitializedServiceInfo(Service service)
   at Autofac.Core.Registration.ComponentRegistry.IsRegistered(Service service)
   at Autofac.ResolutionExtensions.IsRegisteredService(IComponentContext context, Service service)
   at Autofac.ResolutionExtensions.IsRegistered(IComponentContext context, Type serviceType)
RaymondHuy added a commit to RaymondHuy/Autofac that referenced this issue Nov 5, 2019
@tillig tillig closed this as completed in 13ea57d Nov 20, 2019
@delepster
Copy link

Any hint on when the fix will be released?

@tillig
Copy link
Member

tillig commented Dec 9, 2019

It will be released in 5.0. There is no timeline set on 5.0. If you'd like to see a faster 5.0 release, helping out in the form of pull requests is the best way to accelerate the timeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants