1

I created the following constructors for my class:

public class AccountService : IAccountService
{

    public AccountService(Meta meta)
    {
        Initialize(meta.DataSourceID);
    }

    public AccountService(string dataSourceID)
    {
        Initialize(dataSourceID);
    }

However when I call the class:

_accountService = new AccountService(vm.Meta);

I get the following message:

Error 16 The best overloaded method match for 'AccountService.AccountService(string)' has some invalid arguments

Is there something basic that I am missing here? When coding intellisense gives me the two options and there's no syntax error when I use intellisense to select vm.Meta? Do I need to declare constructors in the interface?

5
  • 7
    What is the type of vm.Meta. If vm is an instance of Meta then pass vm instead of vm.Meta. Commented Dec 14, 2011 at 2:55
  • 1
    You in fact cannot declare constructors in the interface as a constructor is considered an implementation detail. Commented Dec 14, 2011 at 2:55
  • The type of vm.Meta is Meta. Actually I tried something else. I completely removed the constructor and then let VS2010 generate a method stub. On compilation that still gives me the error. I'm even more confused now. Commented Dec 14, 2011 at 3:01
  • Does Meta implement any implicit casting operators? Commented Dec 14, 2011 at 3:05
  • All is ok. I couldn´t see anything wrong so I tried it and it compiles well. Commented Dec 14, 2011 at 3:07

1 Answer 1

2

Do I need to declare constructors in the interface?

No. You cannot decalre constructors in an interface. Interfaces represent a declaration of your type's public api; they do not in any way specify how implementing classes are created

The code you have is correct, conceptually at least; the problem is likely that vm.Meta is not of type Meta, or a type that inherits from Meta.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.