Link to home
Start Free TrialLog in
Avatar of dgb
dgb

asked on

Creating my own object using System.Activator.CreateInstance

I am trying create an instance of an object using late binding.
Here is what i did.
make Interface dll
make dll wich implements the interface dll
make standard app wich creates an instance of the dll using late binding.
(System.Activator.CreateInstance)

But it didn't work, i am getting the errormessage
Can't load assembly TestSubService
Dim newTestSubService As Selfmade_Interfaces._ISubService
 
newTestSubService = System.Activator.CreateInstance("TestSubService", "SubService")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgb
dgb

ASKER

One step further, it now says that it can't convert from
System.Runtime.Remoting.ObjectHandle to Selfmade_Interfaces._ISubService

I am using CType for the converting bit
Ok, now it sounds like you are using .NET remoting, so can you tell me what the class looks like, as far as interface implementation, and inheritance?
Avatar of dgb

ASKER

I had to use ObjectHandle.UnWrap now i have an object that i can access.

In short
Dim newObjectHandle as objecthandle
newTestSubService As Selfmade_Interfaces._ISubService

newObjectHandle = System.Activator.CreateInstance("TestSubService", "SubService")
newTestSubService = newObjectHandle.UnWrap

This works
Avatar of dgb

ASKER

Typo

newObjectHandle = System.Activator.CreateInstance("TestSubService", "SubService")

should have been

newObjectHandle = System.Activator.CreateInstance("TestSubService", "TestSubService.SubService")

Thanks