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

Resolving services registered as open generics with implemented interfaces throws ArgumentException #688

Closed
idursun opened this issue Oct 26, 2015 · 3 comments
Labels

Comments

@idursun
Copy link

idursun commented Oct 26, 2015

interface IDouble<T,R> { }
internal interface ISingle<T> :  IDouble<T, int> { }
class CDerivedSingle<T>: ISingle<T> { }
class Program
{
    static void Main(string[] args)
    {
        var builder = new ContainerBuilder();
        builder.RegisterGeneric(typeof (CDerivedSingle<>)).AsImplementedInterfaces();
        var container = builder.Build();
        var resolved = container.Resolve<ISingle<double>>();
    }
}

Resolving service throws the following exception:

ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition.
@tillig tillig added the bug label Oct 26, 2015
tillig added a commit that referenced this issue Oct 26, 2015
@tillig
Copy link
Member

tillig commented Oct 26, 2015

Thanks! I've added the example as a unit test so we can start figuring out what's up.

@idursun
Copy link
Author

idursun commented Oct 26, 2015

Thanks. Exception happens at OpenGenericServiceBinder.cs

I have tried to solve it but couldn't find any way of comparing generic parameter count to serviceGenericArguments count because it seems GetGenericArguments or any similar method is not supported in DNX Core.

Registering component with

 builder.RegisterGeneric(typeof (CDerivedSingle<>)).As(typeof(ISingle<>));

works as expected.

@tillig
Copy link
Member

tillig commented Apr 25, 2017

It only took a year and a half but I figured it out. We're now filtering the list of generic interfaces that we try to fulfill by the number of generic parameters provided. Which is to say, if you only provide a single generic parameter (ISingle<double> -> double) then we don't try to fill in an interface that has two parameters (IDouble<T, U>) because, well, we only have one parameter to work with.

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

No branches or pull requests

2 participants