tonydsouza1987
New member
- Joined
- Sep 1, 2012
- Messages
- 1
- Programming Experience
- 1-3
I have the following Projects :
The server runs fine and the client also registers fine. When the method is called of the remote object (FTObj) via interface on client, I get the below error :
'Attempted to create well-known object of type 'IFTObj.InterfaceFTObj'. Well-known objects must derive from the MarshalByRefObject class'
I have copied the FTObj, IFTObj in the FTHostServer Debug folder and tried, the same. Does that has to do something with another class in FTObj??? The methods of class 'clsSQLDBWrapper' are accessed in 'clsFTObj' class. Helping me in solving the error would be appreciated. I didnt found any help on this error online, even in the below link(which shows exactly my problem) which is still unanswered.
Problems hosting a remote interface
- IFTObj : Interface
- FTObj : Remote object hosted in EXE. This objects inherits MarshalByRefObject and implements the IFTObj interface. In this Object I have two classes 'clsFTObj' and 'clsSQLDBWrapper'. Class 'clsFTObj' inherits MarshalByRefObject. Class 'clsSQLDBWrapper' does not inherits MarshalByRefObject, even though i tried inheriting or making it serilizable after getting the error. The little code of this object is as follows(all the methods are implemeted here) :
VB.NET:
[COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting.Channels
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting.Channels.Tcp
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Data[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Data[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]SqlClient
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] IFTObj[/COLOR][COLOR=#000088]Public[/COLOR][COLOR=#000088]Class[/COLOR][COLOR=#000000] clsFTObj
[/COLOR][COLOR=#000088]Inherits[/COLOR][COLOR=#000000] MarshalByRefObject
[/COLOR][COLOR=#000088]Implements[/COLOR][COLOR=#000000] IFTObj[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]InterfaceFTObj
[/COLOR]
- FTHostServer : Hosting IFTObj. The code is as follows :
VB.NET:
[COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting.Channels
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#880000]Remoting.Channels.Tcp
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Configuration
[/COLOR][COLOR=#000088]Imports[/COLOR][COLOR=#000000] IFTObj
[/COLOR][COLOR=#000088]Public[/COLOR][COLOR=#000088]Class[/COLOR][COLOR=#000000] MDIMain
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] tcpChannel [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] TcpChannel
[/COLOR][COLOR=#000088]Private[/COLOR][COLOR=#000088]Sub[/COLOR][COLOR=#000000] MDIMain_Load[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] sender [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000088]Object[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] e [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]EventArgs[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000088]Handles[/COLOR][COLOR=#000088]Me[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Load
[/COLOR][COLOR=#880000]'load values from app.config file[/COLOR][COLOR=#880000]'Dim FocusDBName As String[/COLOR][COLOR=#880000]'FocusDBName = ConfigurationManager.AppSettings("FocusDBName").ToString[/COLOR][COLOR=#880000]'MessageBox.Show(FocusDBName)
[/COLOR][COLOR=#000088]Try
[/COLOR][COLOR=#880000]RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] props [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] IDictionary [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] Hashtable
props[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"port"[/COLOR][COLOR=#666600])[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"2999"[/COLOR][COLOR=#000000]
props[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"name"[/COLOR][COLOR=#666600])[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#008800]"FTObj"
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] servProvider [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] BinaryServerFormatterSinkProvider [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] BinaryServerFormatterSinkProvider
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] clientProvider [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] BinaryClientFormatterSinkProvider [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] BinaryClientFormatterSinkProvider
servProvider[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]TypeFilterLevel [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Serialization[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Formatters[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]TypeFilterLevel[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Full
tcpChannel [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] TcpChannel[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]props[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] clientProvider[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] servProvider[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000000]
ChannelServices[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]RegisterChannel[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]tcpChannel[/COLOR][COLOR=#666600],[/COLOR][COLOR=#006666]False[/COLOR][COLOR=#666600])
[/COLOR][COLOR=#880000]RemotingConfiguration.RegisterWellKnownServiceType(GetType(IFTObj.InterfaceFTObj), "FTObj", WellKnownObjectMode.SingleCall)
[/COLOR][COLOR=#000088]Catch[/COLOR][COLOR=#000000] ex [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] Exception
MessageBox[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Show[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]ex[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Message[/COLOR][COLOR=#666600])
[/COLOR][COLOR=#000088]End [/COLOR][COLOR=#000088]Try
[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]Sub
[/COLOR][COLOR=#000088]
Private[/COLOR][COLOR=#000088]Sub[/COLOR][COLOR=#000000] MDIMain_FormClosed[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] sender [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000088]Object[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000088]ByVal[/COLOR][COLOR=#000000] e [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Forms[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]FormClosedEventArgs[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000088]Handles[/COLOR][COLOR=#000088]Me[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]FormClosed
ChannelServices[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]UnregisterChannel[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]tcpChannel[/COLOR][COLOR=#666600])
[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]Sub[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]Class[/COLOR]
- FTClient : the code is as follows :
VB.NET:
[COLOR=#000088]Private[/COLOR][COLOR=#000088]Function[/COLOR][COLOR=#000000] registerClient[/COLOR][COLOR=#666600]() [/COLOR][COLOR=#000088]As [/COLOR][COLOR=#000088]Boolean
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] FTObj [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] InterfaceFTObj
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] tcpChannel [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] TcpChannel
[/COLOR][COLOR=#880000]'Made global becoz need to unregister at mdimain form close event.
[/COLOR][COLOR=#000088]Try
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] servProvider [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] BinaryServerFormatterSinkProvider [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] BinaryServerFormatterSinkProvider
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] clientProvider [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] BinaryClientFormatterSinkProvider [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] BinaryClientFormatterSinkProvider
servProvider[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]TypeFilterLevel [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000000] Runtime[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Serialization[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Formatters[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]TypeFilterLevel[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Full
[/COLOR][COLOR=#000088]Dim[/COLOR][COLOR=#000000] props [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] IDictionary [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] Hashtable
props[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"port"[/COLOR][COLOR=#666600])[/COLOR][COLOR=#666600]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#000000]
tcpChannel [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]New[/COLOR][COLOR=#000000] TcpChannel[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]props[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] clientProvider[/COLOR][COLOR=#666600],[/COLOR][COLOR=#000000] servProvider[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000000]
ChannelServices[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]RegisterChannel[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]tcpChannel[/COLOR][COLOR=#666600],[/COLOR][COLOR=#006666]False[/COLOR][COLOR=#666600])[/COLOR][COLOR=#880000]'FTObj = InterfaceFTObj[/COLOR][COLOR=#000000]
FTObj [/COLOR][COLOR=#666600]=[/COLOR][COLOR=#000088]CType[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]Activator[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]GetObject[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]GetType[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]IFTObj[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]InterfaceFTObj[/COLOR][COLOR=#666600]),[/COLOR][COLOR=#008800]"tcp://127.0.0.1:2999/FTObj"[/COLOR][COLOR=#666600]),[/COLOR][COLOR=#000000] InterfaceFTObj[/COLOR][COLOR=#666600])
[/COLOR][COLOR=#880000]'FTMain = Activator.GetObject(Type.GetType("FTMainObj.clsFTMain,FTMainObj"), "tcp://Localhost:2999/FTMain") '- Creates a proxy
[/COLOR][COLOR=#880000]'FTMain = Activator.GetObject(Type.GetType("FTMainObj.clsFTMain,FTMainObj"), "tcp://192.168.55.254:2999/FTMain")
[/COLOR][COLOR=#000088]If[/COLOR][COLOR=#000000] FTObj [/COLOR][COLOR=#000088]Is [/COLOR][COLOR=#006666]Nothing [/COLOR][COLOR=#000088]Then[/COLOR][COLOR=#000000]
MessageBox[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Show[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"Server does not exist, Please make sure you are connected to internet or contact administrator."[/COLOR][COLOR=#666600])[/COLOR][COLOR=#000088]Return[/COLOR][COLOR=#006666]False[/COLOR][COLOR=#000088]End[/COLOR][COLOR=#000088]If[/COLOR][COLOR=#000088]Catch[/COLOR][COLOR=#000000] ex [/COLOR][COLOR=#000088]As[/COLOR][COLOR=#000000] Exception MessageBox[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Show[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000000]ex[/COLOR][COLOR=#666600].[/COLOR][COLOR=#000000]Message[/COLOR][COLOR=#666600])
[/COLOR][COLOR=#000088]End [/COLOR][COLOR=#000088]Try
[/COLOR][COLOR=#000088]Return [/COLOR][COLOR=#006666]True
[/COLOR][COLOR=#000088]End [/COLOR][COLOR=#000088]Function
[/COLOR]
The server runs fine and the client also registers fine. When the method is called of the remote object (FTObj) via interface on client, I get the below error :
'Attempted to create well-known object of type 'IFTObj.InterfaceFTObj'. Well-known objects must derive from the MarshalByRefObject class'
I have copied the FTObj, IFTObj in the FTHostServer Debug folder and tried, the same. Does that has to do something with another class in FTObj??? The methods of class 'clsSQLDBWrapper' are accessed in 'clsFTObj' class. Helping me in solving the error would be appreciated. I didnt found any help on this error online, even in the below link(which shows exactly my problem) which is still unanswered.
Problems hosting a remote interface
Last edited: