Trying to update my GUI from remote object but getting Exception

I'm trying to make some basic chat client/server application using .net remoting.
I want to make windows form client application and console server application as separate .exe files. Here im trying to call server function AddUser from client and i want to AddUser function update my GUI (richtexbox). When i try to do that i get exception: "[italic]SerializationException: Type Topic in Assembly is not marked as serializable[/italic]".

This will work if i use string variable instead of GUI RichTextBox control which im trying to update from another thread. Im begginer with .net remoting and any suggestion how ti fix this is welcome.

Ill post my client/server code bellow...

Thanks.

[b]SERVER code:[/b]

[code]namespace Test
{
public class Topic : MarshalByRefObject
{
[b]public bool AddUser(string user,RichTextBox textBox1,List listBox1)
{
//Send to message only to the client connected
MethodInvoker action = delegate { textBox1.Text += "Connected to
server...
"; };
textBox1.BeginInvoke(action);
//...
return true;
}[/b]

public class TheServer
{
public static void Main()
{

int listeningChannel = 1099;

BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;

BinaryClientFormatterSinkProvider clntFormatter = new
BinaryClientFormatterSinkProvider();

IDictionary props = new Hashtable();
props["port"] = listeningChannel;

HttpChannel channel = new HttpChannel(props, clntFormatter,
srvFormatter);
// Register the channel with the runtime
ChannelServices.RegisterChannel(channel, false);
// Expose the Calculator Object from this Server
RemotingConfiguration.RegisterWellKnownServiceType(typeof
(Topic),
"Topic.soap",
WellKnownObjectMode.
Singleton);
// Keep the Server running until the user presses enter
Console.WriteLine("The Topic Server is up and running on port
{0}", listeningChannel);
Console.WriteLine("Press enter to stop the server...");
Console.ReadLine();
}
}
}
}[/code]

[b]CLIENT CODE:[/b]

[code]// Create and register a channel to communicate to the server
// The Client will use the port passed in as args to listen for
callbacks

private Topic topic;

BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clntFormatter = new
BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 0;

channel = new HttpChannel(props, clntFormatter, srvFormatter);
//channel = new HttpChannel(listeningChannel);

ChannelServices.RegisterChannel(channel, false);
// Create an instance on the remote server and call a method remotely
topic = (Topic)Activator.GetObject(typeof(Topic), // type to create
"http://localhost:1099/Topic.soap" // URI
);


[b]public RichTextBox textbox1;
bool check = topic.addUser(textBoxNickname.Text,textBox1, [/b]listitems);[/code]

Comments

  • A class needs the Serializable attribute on its definition before you can serialize an instantiation of it.

    So your "Topic" class needs this attribute...
    [code]
    [Serializable]
    public class Topic
    {

    }
    [/code]


  • Topic class supposed to be Marshal By Reference. Marking Topic class as Serializable does not change anything as its already inherited from MarshalByRefObject class. Even if i change still get same error. ;)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories