Hi
I have a solution that reads a class & function from another dll without needing to reference it. There is a reason i need to do it this way. anyway it works fine and has done for months on my pc however, im finding that it doesnt work on any workstation either at admin or user level. I have narrows it down to a single line of code. Here is the Class-
Imports System.Reflection
Namespace INVOKER
Public Class C_Invoke
#Region "MEMBERS"
Private _path As String = String.Empty
Private _ClassName As String = String.Empty
Private _FunctionName As String = String.Empty
Private _RegKey As String = String.Empty
#End Region
#Region "PROPERTIES"
Friend Property Path As String
Set(value As String)
_path = value
End Set
Get
Return _path
End Get
End Property
Friend Property ClassName As String
Set(value As String)
_ClassName = value
End Set
Get
Return _ClassName
End Get
End Property
Friend Property FunctionName As String
Set(value As String)
_FunctionName = value
End Set
Get
Return _FunctionName
End Get
End Property
Friend Property RegKey As String
Set(value As String)
_RegKey = value
End Set
Get
Return _RegKey
End Get
End Property
#End Region
#Region "CONSTRUCTORS"
Friend Sub New(ByVal dll_path As String,
ByVal cls_name As String,
ByVal fn_name As String,
ByVal reg_key As String)
Path = dll_path
ClassName = cls_name
FunctionName = fn_name
RegKey = reg_key
End Sub
#End Region
#Region "METHODS"
Public Sub Invoke()
Dim exeConfigPath As String = Path
Dim strCommandName As String = ClassName 'name of class with function being called
Dim assemblyBytes As Byte() = IO.File.ReadAllBytes(exeConfigPath)
Dim objAssembly As Assembly = Assembly.Load(assemblyBytes)
Dim myIEnumerable As IEnumerable(Of Type) = GetTypeSafely(objAssembly)
For Each objType As Type In myIEnumerable
If objType.IsClass Then
If objType.Name.ToLower() = strCommandName.ToLower() Then
Dim iBaseObject As Object = Activator.CreateInstance(objType)
Dim arguments As Object() = New Object() {RegKey}
Dim result As Object = objType.InvokeMember(FunctionName, BindingFlags.[Default] Or BindingFlags.InvokeMethod, Nothing, iBaseObject, arguments)
MsgBox("4")
Exit For
End If
End If
Next
End Sub
Private Shared Function GetTypeSafely(ByVal assembly As Assembly) As IEnumerable(Of Type)
Try
Return assembly.GetTypes()
Catch ex As ReflectionTypeLoadException
Return ex.Types.Where(Function(x) x IsNot Nothing)
End Try
End Function
#End Region
End Class
End Namespace
and this is the line it fails on
Dim result As Object = objType.InvokeMember(FunctionName, BindingFlags.[Default] Or BindingFlags.InvokeMethod, Nothing, iBaseObject, arguments)
Would user restrictions on a workstation prevent this file reading a class and function from another dll? If so, what user restriction would need to be changed in order for it to work again?
Like i said, it works just fine on my machine in multiple solutions, just not on a network workstation...
Thanks