I'm connecting my program to some external code. I'm setting it up so that the external code can instance objects and I've come across a problem. I've created this function here:
Public Function InstanceOf(ByVal typename As String) As Object
Dim theType As Type = Type.GetType(typename)
If theType IsNot Nothing Then
Return Activator.CreateInstance(theType)
End If
Return Nothing
End Function
I'm trying to create a System.Diagnostics.Process
object. For what ever reason though, it always return Nothing
instead of the object. Does anybody know what I'm doing wrong?
I'm doing this in VB.net so all .net responses are accepted :)
Read carefully through the documentation of
Type.GetType()
, specifically, this part:Since
System.Diagnostics.Process
is in System.dll (not Mscorlib.dll), you need to use the fully qualified name. Assuming you're using .Net 4.0, that would be:If you don't want to work with fully qualified names, you can go through all loaded assemblies and try to get the type using
Assembly.GetType()
.