-3

I've read through some of the other posts that are related but I don't believe I have the same problem that they do. I believe I'm doing my constructor for my inherited class properly, however it still won't work - and won't even recognize that I have a constructor there it seems.

class BlockedNumber : PhoneNumber
{
    public BlockedNumber(string a, string m, string l)
        : base(a, m, l) { }
}

This still gives me the error in the title:

"DTS.PhoneNumber does not contain a constructor that takes 0 arguments.

I don't know why it isn't recognizing my constructor properly. The error (blue underline in VS12) is on the first use of BlockedNumber right after class.

Does anyone have any idea why it doesn't like that?

Ian R. O'Brien
  • 6,682
  • 9
  • 45
  • 73
  • 1
    What is the code where you are creating the `BlockedNumber` object? – PiousVenom Mar 22 '13 at 21:31
  • So you are getting a compile error, or a "phantom designer error"? Sometimes VS uses old files for its autocomplete, it's rare but does happen, so try a rebuild and see if the problem is still there... – theMayer Mar 22 '13 at 21:36
  • you mean try to do a `Clean` then a `Rebuild` don't you.. – MethodMan Mar 22 '13 at 21:37
  • I would recommend adding the constructor for PhoneNumber here – JerKimball Mar 22 '13 at 21:42
  • Hayden, do you have your complete base class code ? Can you copy it here ? – Jasmine Mar 22 '13 at 21:54
  • Possible duplicate of [C# Error: Parent does not contain a constructor that takes 0 arguments](http://stackoverflow.com/questions/7230544/c-sharp-error-parent-does-not-contain-a-constructor-that-takes-0-arguments) – Jim Fell Jun 02 '16 at 17:58

4 Answers4

2

The following compiles

class BlockedNumber : PhoneNumber
{
    public BlockedNumber(string a, string m, string l)
        : base(a, m, l) { }
}

internal class PhoneNumber
{
    public PhoneNumber(string a, string m, string l) { }
}

Your issue is elsewhere. Most likely you're instantiating a PhoneNumber somewhere else with 0 arguments.

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142
2

if you do not directly specify : base(x,y,z) i.e. which parent constructor to call, compiler tries to find a parent constructor without parameters to call by default.

it is explained in this post - C# Error: Parent does not contain a constructor that takes 0 arguments

Community
  • 1
  • 1
Aedna
  • 761
  • 6
  • 5
0

Most likely your child class has yet another parameterless constructor which you don't reveal but the constructor doesn't call the base class constructor in an explicit way. Because of that, you assume that it is not relevant. However, C# inserts a base class constructor call to every single constructor because this is required in CIL. Thus, the other constructor complains that it is not able to find a base class constructor to call.

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
-1

Taking what you have and Generating a class from VS2010

internal class PhoneNumber
    {
        private string a;
        private string m;
        private string l;

        public PhoneNumber(string a, string m, string l)
        {
            // TODO: Complete member initialization
            this.a = a;
            this.m = m;
            this.l = l;
        }
    }

class BlockedNumber : PhoneNumber
{
    public BlockedNumber(string a, string m, string l)
        : base(a, m, l) { }
}

This code compiles just fine so just like Yuriy stated the issue must be somewhere else.

MethodMan
  • 18,625
  • 6
  • 34
  • 52