I’m trying to use reflection to access a custom assembly that I’ve created. Specifically I’m trying to access a public list of a structure that I’ve created. (It is a list of Holiday structures which define public holidays.) I’m sure I’m missing something basic but I keep getting this strange error in the IDE.
Dim f As New OpenFileDialog() With { ... }
Dim rgAsm as Reflection.Assembly
Dim rgType as Type
Dim rgDLL as Object
rgASM = Reflection.Assembly.LoadFile(f.Filename)
rgType = rgAsm.GetType("rgReporting.rgReporting")
rgDLL = Activator.CreateInstance(rgType)
Dim holType As Type = modConf.rgAsm.GetType("rgReporting.PublicHolidays+Holiday")
If holType Is Nothing Then MsgBox("no.") Else MsgBox("yes!")
When I run the code above I get the “yes!” msgbox meaning that my type has been defined by GetType(). However when I try to write the following code:
Dim blah as holType
The IDE gives me this error: “Type ‘holType’ is not defined.”
I’m looking to use the type in a for each in the end, but doing that gives the same error. I realize I’m missing some basic step in defining the type as something that can be used but I can’t seem to find what it is.
You can’t do that. In order to define a variable like that of type holType it has to be statically defined. holType is a runtime type.
In order to create an instance of holType you can write: