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

Visual Basic.NET

Avatar of undefined
Last Comment
dgb

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bob Learned

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
dgb

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
Bob Learned

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?
ASKER
dgb

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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
dgb

Typo

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

should have been

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

Thanks