C# & .NET Remoting: "not marked as serializable" -- but it is!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mmfranke
    New Member
    • Nov 2006
    • 1

    C# & .NET Remoting: "not marked as serializable" -- but it is!

    Hello.

    Hi.

    I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it DiagnosticEvent objects for processing.

    I've altered the main program for the service slightly so that I can run it more easily as a "regular" application during debugging. I have an assembly that contains the "diagnostic s" classes that do the work, the service app itself, and a test client app that lets you create a DiagnosticEvent and "dispatch" it.

    That is, I'm trying to pass an argument to a member function of a remotable object. As I understand it, that means I have to mark it as serializable, which I have.

    The problem is that I'm getting errors telling me that the DiagnosticEvent object which I'm passing to the remote object is "not marked for serialization" -- even though it is. When I try adding a function that takes a TestObject, expecting the same error, I then get an exception about "unable to load" due to a problem with deserialization .

    I'm clearly missing something basic. I'm new to .NET, BTW.

    (ASIDE: One more little hitch is that I've been wrestling with static initialization of the remote object. It's a singleton class, and it seems that I get messed up if the server application instantiates the class before remote applications get a chance to. But perhaps that's for another post.)

    Can someone help me clear up my serialization issues? Here's some of the code:

    The object I'm passing to the remote object is declared as:
    Code:
    [Serializable]
    public class DiagnosticEvent : ISimObject
    { . . . }
    ...and so is my TestObject:
    Code:
    [Serializable]
    public class TestObject
    {
    public int m_Int;
    public string m_String;
    }
    Here's the code where the remote object is served up:

    Code:
    private static TcpChannel Publish()
    {
    TcpChannel channel = null;
    
    if (channel == null)
    {
    // Create an instance of a channel
    channel = new TcpChannel(8080);
    ChannelServices.RegisterChannel(channel, false);
    }
    
    // Register as an available service with the name GEDiag
    RemotingConfiguration.RegisterWellKnownServiceType(
    typeof(GESim.Diagnostics.EventProcessor),
    "GEDiag",
    WellKnownObjectMode.Singleton);
    
    return channel;
    }
    Here's the code where the client connects to the remote object:

    Code:
    private void ConnectToEventProcessor()
    {
    // Create a channel for communicating w/ a remote object
    // Notice no port is specified -- because we're the client.
    if (null == s_Channel)
    {
    s_Channel = new TcpChannel();
    ChannelServices.RegisterChannel(s_Channel, false);
    }
    
    if (null == m_RemoteEventProcessor)
    {
    // Create an instance of the remote object
    m_RemoteEventProcessor =
    (EventProcessor)Activator.GetObject(
    typeof(EventProcessor),
    "tcp://T00472343:8080/GEDiag");
    }
    }
    ...and finally, the code where the remote object is exercised -- both with a TestObject and with the actual DiagnosticEvent object. Neither work, for the different reasons I mentioned above:

    Code:
    TestObject testObject = new TestObject();
    testObject.m_Int = 45;
    testObject.m_String = "Testing 123...";
    
    int i = m_RemoteEventProcessor.Test(testObject);
    
    m_RemoteEventProcessor.EnqueueEvent(theEvent);
    I'd be happy to send the solution (I've sculpted it down to something minimal).

    Thanks, in advance.
Working...