1

I've seen several questions and answers about this issue, but couldn't find one that enabled me to solve the problem.

The project is a C# .NET project.

The error i'm getting is:
"InvalidOperationException - The type MyTypeName has multiple constructors of length 2. Unable to disambiguate."

Granted, there are several constructors that accept 2 parameters, but there are several similar classes in the same project, and they all have these constructors (same prototype - with a different name of course).

The new class i've added has constructors with the same signatures as the other classes, but for some reason, when resolving this class, I get the above error.

I always manage to configure unity correctly and debug it, but this time i'm at a loss.

Where should i look?

Edit:

Here are the class constructors. the whole class is pretty big, so i'm trying to post only the relevant part:

    public CategorizationServiceProxy() {
    }

    public CategorizationServiceProxy(string endpointConfigurationName) : 
            base(endpointConfigurationName) {
    }

    public CategorizationServiceProxy(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public CategorizationServiceProxy(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public CategorizationServiceProxy(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress) {
    }

Another Edit:

And here is the unity configuration for the above class. There are 9 other classes, all configured exactly the same way, and they all instantiate correctly.

<register
    type="SA.Contracts.CategorizationService.ICategorizationService, SA.Contracts, PublicKeyToken=5021cc32571ca775"
    mapTo="SA.Service.Categorization.CategorizationServiceImpl, SA.Service.Categorization, PublicKeyToken=5021cc32571ca775" >
    <lifetime type="singleton" />
  </register>

Thanks.

roniSA
  • 31
  • 6
  • Do the other classes have a constructor with more parameters than 2? That seems to be what [this answer to another question](http://stackoverflow.com/a/11106692/12570) is saying: perhaps your new class does not have a constructor that takes, say, 3 parameters... and the previous classes do. Either that, or unity is explicitly told which 2-parameter constructor to us. – Peter K. Apr 14 '13 at 14:07
  • 3
    You should post the code of that class, it would help greatly. – LightStriker Apr 14 '13 at 14:08
  • Thanks. I've added the class constructors. – roniSA Apr 14 '13 at 17:19
  • @PeterK. - That's the weird thing - all of the classes have exactly the same constructors, and they are similarly configured in unity. No constructor is specified in unity.config for any of the classes. – roniSA Apr 14 '13 at 17:21
  • 1
    One of your constructors has to have the InjectionConstructor attribute to remove the ambiguation. – Wiktor Zychla Apr 14 '13 at 17:25
  • @WiktorZychla - I think that's what i would have to do. It just seems strange that the same configuration works for 7-8 other classes without specifying an InjectionConstructor. Can't seem to figure it out :-) – roniSA Apr 15 '13 at 08:02
  • possible duplicate of [Multiple implementations for one interface with DI](http://stackoverflow.com/questions/15943569/multiple-implementations-for-one-interface-with-di) – jgauffin Apr 15 '13 at 08:17
  • The question that I linked to is different, but the answer applies. The IoC is not a factory. Do not create your proxy directly through it (you can register a factory method in it though) – jgauffin Apr 15 '13 at 08:19
  • Please post the unity configuration for the class in question. – Chris Tavares Apr 17 '13 at 22:39
  • @ChrisTavares Thanks. I've added the configuration. – roniSA Apr 22 '13 at 12:30
  • your class is `CategorizationServiceProxy` but in the unity configuration you are mapping to `CategorizationServiceImpl`. Is it a typo? – Jehof Apr 22 '13 at 12:37
  • @Jehof - Thanks for your answer. All of the classes i use are mapped this way - from the interface to the class that implements it. – roniSA Apr 22 '13 at 16:20

0 Answers0