Remoting, Events, Interfaces and Assemblies
Greetings,
I have a test program that I am playing with which uses interfaces to instantiate remote objects. The interface is defined in one assembly, with an EventRepeater class which should handle the registration and firing of an event raised from the server. A server object which implements my interface is defined in a different assembly while the actual server application is defined in a third. And finally, my client is defined in a separate assembly that will reside of course on the client machine. The Server class assembly has a reference to the Interface library as does the server application and the client. The client does not contain a reference to the server assembly, nor should it need to as this is "Remoting" afterall. When I start my server, everything runs fine. When I start my client everything is fine until I get to this line:
VB Code:
AddHandler m_IJobServer.JobEvent, AddressOf m_JobEventRepeater.Handler
This is the entire code from the client:
VB Code:
Imports System
Imports System.Runtime.Remoting
Imports JobLib
Public Class Client : Inherits System.Windows.Forms.Form
Private m_IJobServer As IJobServer
Private m_JobEventRepeater As JobEventRepeater
Private Function GetIJobServer() As IJobServer
RemotingConfiguration.Configure("..\App.config")
Dim obj As Object = RemotingHelper.GetObject(GetType(IJobServer))
Return DirectCast(obj, IJobServer)
End Function
Private Sub JobEventRepeater_JobEventHandler(ByVal sender As Object, ByVal args As JobEventArgs)
MessageBox.Show(args.Reason)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call m_IJobServer.CreateJob("My New Job")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Client_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_IJobServer = GetIJobServer()
m_JobEventRepeater = New JobEventRepeater
AddHandler m_JobEventRepeater.JobEvent, AddressOf Me.JobEventRepeater_JobEventHandler
[COLOR=red]AddHandler m_IJobServer.JobEvent, AddressOf m_JobEventRepeater.Handler[/COLOR]
End Sub
End Class
Class RemotingHelper
Private Shared _isInit As Boolean
Private Shared _wellKnownTypes As IDictionary
Public Shared Function GetObject(ByVal _type As Type) As Object
If Not _isInit Then Call InitTypeCache()
Dim Entry As WellKnownClientTypeEntry = DirectCast(_wellKnownTypes(_type), WellKnownClientTypeEntry)
If (Entry Is Nothing) Then Throw New RemotingException("Type not found!")
Return Activator.GetObject(Entry.ObjectType, Entry.ObjectUrl)
End Function
Public Shared Sub InitTypeCache()
_isInit = True
_wellKnownTypes = New Hashtable
For Each Entry As WellKnownClientTypeEntry In RemotingConfiguration.GetRegisteredWellKnownClientTypes
If Entry.ObjectType Is Nothing Then Throw New RemotingException("A configured type could not be found. Please check spelling")
_wellKnownTypes.Add(Entry.ObjectType, Entry)
Next
End Sub
End Class
This is the config file for the client:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="JobClient">
<client>
<wellknown type="JobLib.IJobServer, JobLib" url="tcp://localhost:81/JobServer" />
</client>
<channels>
<channel ref="tcp" port="0">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
The error I am receiving is:
Additional information: Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.
and I have come to understand that you receive this error when you have not set the typeFilterLevel to "Full". I have done this as can be seen in the configuration file above.
I have sent Ingo Rammer a couple of emails but I guess with his busy schedule he has not had time to respond. Do any of you have any thoughts on what might be causing my application to throw this exception?
Any help or suggestions would be greatly appreciated (provided they work:))