473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Reflecting a type and casting causes error

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

Feb 24 '06 #1
0 940

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Enekajmer | last post by:
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 }
1
by: Paul E Collins | last post by:
I'm using XmlSerializer.Serialize method from System.Xml.Serialization on one of my own classes and getting the following error: "An unhandled exception of type 'System.InvalidOperationException'...
1
by: OrionLee | last post by:
I am using C# to work with a 3rd party DLL (Nevron Charts), and attempting to serialise it. The serialisation itself is handled somewhere inside the DLL, so to get it to happen you call the Nevron's...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.