tennis779
tennis779

Reputation: 348

Instantiating a class with no constructor

I am trying to use a class that unfortunately does not have a constructor defined. When I try to create the object C# tells me that there is no predefined constructor. I was told that this class was created in Visual Basic 6 many years ago, and that somehow in VB the constructor was not needed.

Can anyone think of any solutions for this problem. Maybe a I could declare a new class and inherit the old one. Then in the new class I could create the constructor.

    someClass  myClass= new someClass();
    //Returns an error saying no constructor can be found at all.

Upvotes: 1

Views: 2105

Answers (1)

ispiro
ispiro

Reputation: 27633

It might have an internal constructor. See this answer. This would mean you won't be able to access the constructor from a different assembly. (See MSDN.)

There might be some method in that assembly that instantiates an instance of that class. Try finding a method like that, and call it to get an instance of someClass.

Upvotes: 3

Related Questions