tags:

views:

68

answers:

1

I have what I thought was a simple .NET Remoting Client/Server (Code Below)... When hosting/running in a Console application it works fine, but when hosted in a Windows Service, all calls to members of proxies returned from Activator.GetObject result in a NullReferenceException.

To simplify things I placed all this in a single Console and it worked fine... Created a basic Windows Service and placed the same code on the OnStart method and once I access the "TheString" property I get a NullReferenceException.

I can confirm there are no other exceptions, the ports are available, and the service is run as an administrator. Also, my solution will require a singleton which is why I am using that.

At the moment this is being hosted on Windows 7 which may be a factor. If I could learn how to see more of what underlying error may be causing this, I may be able to figure it out... How can I see what might be happening underneath (ex. sink, formatter, etc...)?

Server Code:

var provider = new BinaryServerFormatterSinkProvider
{
    TypeFilterLevel = TypeFilterLevel.Full
};

IDictionary properties = new Hashtable();
properties["port"] = 20001;
properties["exclusiveAddressUse"] = false;

_channel = new TcpChannel(properties, null, provider);

ChannelServices.RegisterChannel(_channel, false);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(HostClass), "TheHost", WellKnownObjectMode.Singleton);

Client Code:

var retInstance = (HostClass)Activator.GetObject(typeof(HostClass),
    string.Format("tcp://{0}:{1}/TheHost", "MyHostName", 20001));

string host = retInstance.TheString; //This is where the NullReference is experienced

Remoting Object:

public class HostClass : MarshalByRefObject, IHostClass
{
    public HostClass()
    {
      TheString = "Hello World";
    }

    public override object InitializeLifetimeService()
    {
        return null;
    }

    public string TheString { get; set; }
}

Any ideas would be appreciated.

A: 

As it turns out the limitation relates to the remoting engines inability to serialize and proxy interface types, which while not part of my sample (sorry) was ultimately the root of the issue.

JoeGeeky