Hi all,
The following code is meant to be used to load a class from an assembly
and return a property from it. The class being loaded will always
inherit from the base class of MyLicenceBase. However, I just cannot
get past the CType below when trying to convert the loaded class to the
proper base type. Is it possible to do this? I am doing this cast
elsewhere in my code (but not using reflection) so I can't see why it
won't work here. I'd rather not do an invoke using strings to define
the parameters etc.
Any help appreciated very much...
Function CheckClass(ByVal AssemblyPath As String, ByVal
AssemblyType As String) As String
Dim AssemblyToLoad As Assembly
Dim BaseObject As Licencing.MyLicenceBase
Dim TempObject As Object
AssemblyToLoad = Assembly.LoadFrom(AssemblyPath)
' The following should fire the default constructor for the
class.
TempObject = AssemblyToLoad.CreateInstance(AssemblyType)
' The class we instantiated inherits from a base type, cast
to that so we can programmatically access properties.
' The following line generates an InvalidCastException!
BaseObject = CType(TempObject, Licencing.MyLicenceBase)
' Return a test property from the class.
Return BaseObject.Title
End Function
Thanks
Ryan