T
T
Timofey Yatsenko2013-06-07 15:18:27
.NET
Timofey Yatsenko, 2013-06-07 15:18:27

No constructor defined for type 'TypeName' when class is overridden?

I can't figure out what the problem is. I'm new to C# and have never encountered this problem before.
Google answers are also off topic.
In general, when trying to inherit a certain class, it displays such a message. The class itself is inside a third party compiled assembly.
I looked at the assembly using Reflector, it is clear that the constructor has the visibility modifier internal.

The internal keyword is an access modifier for types and type members. Internal types or members are only accessible inside files in the same assembly

In general, I tried to write my own constructor in an overridden class - the problem remained.
Whether it is possible to redefine such class in general as or to (to be inherited)?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
G
groaner, 2013-06-07
@groaner

It is forbidden.

A
Andrei Smirnov, 2013-06-08
@pinebit

You can if you add the InternalsVisibleTo attribute in the source assembly in the manifest . How to add such an attribute to the compiled assembly is a separate topic.
This is also used in assembly testing so that separate tests in separate assemblies can access internal classes that are also subject to testing.

G
Georgy Grigoriev, 2013-06-07
@IamKarlson

MSDN makes it clear that you cannot access these classes, let alone inherit from them.

P
p1x, 2013-11-13
@p1x

As stated above, it is not possible. But if you really want to, then you can . But it's better not to do that.

A
Alexander Vishnyakov, 2013-11-19
@asvishnyakov

If internal is the class itself, then it is impossible in any way.
If internal is the default constructor and there are no other public constructors, then it is also impossible.
If there is a public constructor with parameters, and you want to define a default one (without parameters) in your class, then you need to do something like this:
let's say the parent class constructor is like this:

public A(int param)
{
}

then your constructor will be like this:
public B() : base(0)
{
}

where 0 is the default value you want to pass;
if you also need a constructor with a parameter, then like this:
public B(int a):  base(a)
{
}

Now why. There is such concept - accessibility (visibility). In the first case, the class is internal and you can't see it at all. In the second, you cannot create an instance of it through the constructor and, accordingly, inherit from it, since the constructor itself is not visible to you. I described the solution to the third problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question