I'm getting the following SerializationException as Server calls client event method:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed."
I can call methods on the remote object from the client. This started working when I set the typeFilerLevel to "Full" in the server app.config. I was getting the same exception in the client code, so my logic says I need the same option set on the client. The server will change so I have to do this programatically in the client.
Soooo, can I do this on the client side when using Activator.GetObject The doc for Activator.GetObject is awful, especially, for the third argument which is what I think I need to use for this.
Thanks,
Dave

Activator.GetObject third argument.
Infinite Dimentia
this is the client side code.
Hashtable props = new Hashtable();
TcpChannel chan = new TcpChannel(props, null, serverProvider);props.Add("port", "0");
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Console.WriteLine("Registering channel");
ChannelServices.RegisterChannel(chan);
serverObj =
Activator.GetObject(typeof(ServerType), "tcp://localhost:8099/ServerObj") as ServerObj;serverObj.Method(
true, false, null ); // works string workDir = serverObj.WorkingDirectory; // worksserverObj.TheInt = 10; // works
int i = serverObj.TheInt; // worksserverObj.ExecuteCompleted += this.ExecuteCompleted; // works here but fails when called.
ClientObject clientObj = new ClientObject();
serverObj.ClientObj = clientObj; // works. can call a method on this obj in the server.
Here is the server's app.config.
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="Type, Assemby" objectUri="ServerObj" />
</service>
<channels>
<channel ref="tcp" port="8099">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
thanks,
Dave
RJButler
Two painful days but I learned alot. IMO, I should get a similar error at complile time without remoting. Why allow private methods to be event callbacks if it can't be remoted that way
Thanks! Hope you didn't spend too much time on this one.
private void ExecuteCompleted( object sender, MyNamespace.ExecuteCompletedEventArgs e )
erossetto
1. A delegate is created (in your case, implicitly, although I never realized this could compile :-)). The delegate is a value-object, and references your object which presumably derives from MarshalByRefObject.
2. When the server fires the event, as I explained earlier, your client application essentially becomes a remoting SERVER itself. The server references your remote object, meaning the exact same remoting infrastructure is used to invoke the method the delegate points to.
3. This has the two side-effects: it requires the client to define an incoming port (which you did by registering a TCP channel); also, it requires the client object to adhere to all the standard remoting rules (one of them being that private and static methods cannot be invoked remotely).
Hope this clarifies some things. Be advised that as long as you're using events you may want to consider using a shimming technique to avoid the ubiquitous "server does not recognize client DLL" issue. You can find explanations and sample code here.
Nikolaos Wakem
To get over this programmatically you need to open a port on the client (use port 0, which instructs the remoting infrastructure to use whichever incoming port is available) and set the TypeFilterLevel on its BinaryServerFormatterSinkProvider to Full:
Hashtable props = new Hashtable();
props.Add( "port", "0" );
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
TcpChannel chan = new TcpChannel( props, null, serverProvider );
Console.WriteLine( "Registering channel" );
ChannelServices.RegisterChannel( chan );
Ian Jagger
What does the declaration for ExecuteCompleted look like