Connecting Tech Pros Worldwide Forums | Help | Site Map

C# Unable to create instance : class implementing interface

MKoleoso
Guest
 
Posts: n/a
#1: Jul 19 '05
Problem: C#- Unable to create instance of a class
implementing from an interface

I have:

namespace someNamespace
{
public __gc class SomeClass1
{
}

public __gc class SomeClass2: public ISomeInterface
{
}
}

I'm trying to create instances of them both using
Assembly.CreateInstance("..."),
but SomeClass2 fails because it is flagged as an abstract
class. I get the exception:
Cannot create an abstract class.

What do I need to be able to create instances of classes
implementing interfaces?

Regards,
Mike

MKoleoso
Guest
 
Posts: n/a
#2: Jul 19 '05

re: C# Unable to create instance : class implementing interface


OK, the loaded DLL is in C++.NET, but the common
interfaces DLL and the loader are in C#

I solved the problem by deriving from a class within the
dynamically loaded DLL, instead of trying to derive from
an interface.

I put a default implementation class of the interface into
a common DLL, which I then derive from in the dynamic
module. This gives me a valid instance, so the problem is
solved for me.

Thanks for the response,
Mike
[color=blue]
>-----Original Message-----
>MKoleoso <mkoleoso@cae-gmbh.de> wrote:[color=green]
>> Problem: C#- Unable to create instance of a class
>> implementing from an interface
>>
>> I have:
>>
>> namespace someNamespace
>> {
>> public __gc class SomeClass1
>> {
>> }
>>
>> public __gc class SomeClass2: public ISomeInterface
>> {
>> }
>> }
>>
>> I'm trying to create instances of them both using
>> Assembly.CreateInstance("..."),
>> but SomeClass2 fails because it is flagged as an[/color][/color]
abstract[color=blue][color=green]
>> class. I get the exception:
>> Cannot create an abstract class.
>>
>> What do I need to be able to create instances of[/color][/color]
classes[color=blue][color=green]
>> implementing interfaces?[/color]
>
>With the code you posted above, it should be okay.[/color]
(Having said that,[color=blue]
>I'm not sure what the __gc bit is doing there - I thought[/color]
that was a[color=blue]
>managed C++ thing?)
>
>Could you post a short but complete program demonstrating[/color]
your problem?[color=blue]
>See http://www.pobox.com/~skeet/csharp/complete.html
>
>--
>Jon Skeet - <skeet@pobox.com>
>http://www.pobox.com/~skeet/
>If replying to the group, please do not mail me too
>.
>[/color]
Closed Thread