|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DirectCast of object to interface doesn't workI am trying to load an assembly at runtime (plugin). Having the object (as Object), I like to cast it to the interface. The interface is defined as follows: Public Interface IVoimDescriptor Function getVendorName() As String Function getVoimDescription() As String '... End Interface The class, I get, is defined as follows: Public Class VoimDescriptor Implements IVoimDescriptor Public Function getVendorName(ByVal i As Integer) As String Implements IVoimDescriptor.getVendorName End Function Public Function getVoimDescription() As String Implements IVoimDescriptor.getVoimDescription End Function End Class Trying to cast the object to IVoimDescriptor fails with InvalidCastException. Why, and how could I do this ? The Plugin implements classes based on interfaces and only the interfaces are public. Thanks, Lothar assem = assem.LoadFrom(cbPlugins.SelectedItem) Dim o As Object = assem.CreateInstance("SampleVoim.VoimDescriptor") Dim descriptor As IVoimDescriptor = DirectCast(o, IVoimDescriptor) ' <<<<<<<<< txtDesc.Text = descriptor.getVoimDescription() Hi,
I have solved it :-) Creating an assembly with only that interfaces and referencing to it helped. Regards, Lothar lothar.behr***@lollisoft.de wrote: Show quoteHide quote > Hi, > > I am trying to load an assembly at runtime (plugin). Having the object > (as Object), I like to > cast it to the interface. The interface is defined as follows: > > Public Interface IVoimDescriptor > Function getVendorName() As String > Function getVoimDescription() As String > '... > End Interface > > The class, I get, is defined as follows: > > Public Class VoimDescriptor > Implements IVoimDescriptor > > Public Function getVendorName(ByVal i As Integer) As String > Implements IVoimDescriptor.getVendorName > > End Function > > Public Function getVoimDescription() As String Implements > IVoimDescriptor.getVoimDescription > > End Function > End Class > > > Trying to cast the object to IVoimDescriptor fails with > InvalidCastException. > > Why, and how could I do this ? > > The Plugin implements classes based on interfaces and only the > interfaces are public. > > Thanks, Lothar > > assem = assem.LoadFrom(cbPlugins.SelectedItem) > Dim o As Object = > assem.CreateInstance("SampleVoim.VoimDescriptor") > > > Dim descriptor As IVoimDescriptor = DirectCast(o, > IVoimDescriptor) ' <<<<<<<<< > > txtDesc.Text = descriptor.getVoimDescription() <lothar.behr***@lollisoft.de> schrieb:
> I am trying to load an assembly at runtime (plugin). Having the object Plug-ins and cast exceptions > (as Object), I like to cast it to the interface. >[...] > Trying to cast the object to IVoimDescriptor fails with > InvalidCastException. <URL:http://www.yoda.arachsys.com/csharp/plugin.html> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Calling Sub Procedure with a variable
ISO-8859-1 encoding of an xml string Deleting a Photo stored in a Picturebox Old Basic commands. VB.NET 2002 question from complete and utter newbie to programming programatically created checkboxes within panels again.... Lauching a form from another form How to remove an empty array ? Strict type for Hashtable? Dataset to excel |
|||||||||||||||||||||||