-2

I have been provided a 3rd party DLL.

I first tried to initiate the object like so:

TestClass MyClass = new TestClass();

But Visual Studio tells me to use the Interface.

I've never done this before and don't know where to start.

The error:

The Type 'MyClass.blabla' has no constructors defined Interope type 'MyClass.Subclass' cannot be embedded. Use the applicable interface instead.

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
Anonymous
  • 575
  • 1
  • 4
  • 11
  • What interface is it telling you to use? Could you post the exact error message in your question? – JaredPar Mar 19 '13 at 15:44
  • As long as 3rd party DLL provides interfaces, if not you can use `var` keyword – cuongle Mar 19 '13 at 15:44
  • The Type 'MyClass.blabla' has no constructors defined Interope type 'MyClass.Subclass' cannot be embedded. Use the applicable interface instead. – Anonymous Mar 19 '13 at 15:55

3 Answers3

2

This is likely because you're using a COM class. If that is the case, you'll most likely want to write:

ITest myTest = new TestClass();

COM wrappers frequently expose an ITest interface via a CoClass named TestClass. However, when using COM, you're (by design) typically only writing against the interface (ITest), and wouldn't want to write against the implementation directly.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
0

It entire depends on how the TestClass is declared. If TestClass is abstract you cannot create its instance directly, instead you have to create Instance from one of the class Derived from TestClass.

TestClass test = new TestClassDerived();

where

class TestClassDerived : TestClass
{

}
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
  • I tried this but it wants me to implement all of the TestClass functions within my TestClassDerived. There are hundreds. I just want access to the functions already within the DLL. – Anonymous Mar 19 '13 at 15:48
  • If there are 100's of Method they you have to write it! That is how Object Oriented programming works. – Parimal Raj Mar 19 '13 at 15:49
  • Visual Studio generates all the needed Methods, so its not much of a worry if you just need to use the existing non-abstract method.! – Parimal Raj Mar 19 '13 at 15:50
0

It might be providing you some kind of initialization methods or being passed as constructors. You can not instantiate an abstract class or an interface the way you are trying to do (i.e. calling constructor)

Yahya
  • 3,386
  • 3
  • 22
  • 40