A
Andy Franks
Hi All,
This is driving me nuts, especially since I have this working for
my main application with no problem. I suspect it might be due to
Namespace conflicts, but I'm not positive. Any help is vastly
appreciated.
This is part of a routine for switching between using local and remote
business logic libraries. Essentially, it's a fairly simple
late-binding routine. However, When I try to cast oLocalObject to
the IMyInterface, I get an Invalid Casting exception. However, If I
use early-binding (not an option, unfortunatly) this casting works.
The casting also works in the Remoting option (not included here).
Here's how the objects look:
(Yes, both assemblies share the same namespace. This is needed to
have the interface work for remoting)
MyApp.exe
MyCompany.MyApp.IMyInterface
MyApp.dll
MyCompany.MyApp.IMyInterface
MyCompany.MyApp.CMyClass (Implements MyCompany.MyApp.IMyInterface)
Code:
Dim oType As Type, oMod As [Module]
Dim oLocalObject As Object
Dim oReturnValue As MyCompany.MyApp.IMyInterface
oMod = [Assembly].LoadFile(msLibPath +
"MyApp.dll").GetModules(False)(0)
oType = oMod.GetType("MyCompany.MyApp.CMyClass", False)
oLocalObject = Activator.CreateInstance(oType)
Try
'This is Just added to prove the point that it should
be able to cast this.
If oLocalObject.GetType.GetInterfaces(0).FullName =
"MyCompany.MyApp.IMyInterface" Then _
oReturnValue = CType(oLocalObject,
MyCompany.MyApp.IMyInterface)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return oReturnValue
TIA,
Andy
This is driving me nuts, especially since I have this working for
my main application with no problem. I suspect it might be due to
Namespace conflicts, but I'm not positive. Any help is vastly
appreciated.
This is part of a routine for switching between using local and remote
business logic libraries. Essentially, it's a fairly simple
late-binding routine. However, When I try to cast oLocalObject to
the IMyInterface, I get an Invalid Casting exception. However, If I
use early-binding (not an option, unfortunatly) this casting works.
The casting also works in the Remoting option (not included here).
Here's how the objects look:
(Yes, both assemblies share the same namespace. This is needed to
have the interface work for remoting)
MyApp.exe
MyCompany.MyApp.IMyInterface
MyApp.dll
MyCompany.MyApp.IMyInterface
MyCompany.MyApp.CMyClass (Implements MyCompany.MyApp.IMyInterface)
Code:
Dim oType As Type, oMod As [Module]
Dim oLocalObject As Object
Dim oReturnValue As MyCompany.MyApp.IMyInterface
oMod = [Assembly].LoadFile(msLibPath +
"MyApp.dll").GetModules(False)(0)
oType = oMod.GetType("MyCompany.MyApp.CMyClass", False)
oLocalObject = Activator.CreateInstance(oType)
Try
'This is Just added to prove the point that it should
be able to cast this.
If oLocalObject.GetType.GetInterfaces(0).FullName =
"MyCompany.MyApp.IMyInterface" Then _
oReturnValue = CType(oLocalObject,
MyCompany.MyApp.IMyInterface)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return oReturnValue
TIA,
Andy