SharedMemory Channel - GenuineChannels/GenuineChannels GitHub Wiki

Using the SharedMemory Channel with Windows Vista and above

By Henning Krause

If you are using the shared memory remoting channel from GenuineChannels under Vista, you can quickly become a victim of a new security feature of Windows Vista: Global objects (a Mutex in the global namespace, for example) can only be created in session 0 - and with Vista, only services run in session 0.

The GenuineChannels SharedMemoryChannel creates a global mutex by default, and will fail with with this error message:

Can not create or open a memory file mapping.
Error code: 2. Use the Visual C++ Error Lookup utility to see the text of the error message.

Consider the following code for the initialization of the remoting infrastructure:

public void InitializeRemoting(string name, string address)
{
    var properties = new Hashtable();
    properties["listen"] = address;
    properties["name"] = name;
    properties["priority"] = 100;

    var channel = new GenuineSharedMemoryChannel(properties, null, null)
    ChannelServices.RegisterChannel(channel);
}

To force the channel to create session-local objects only, add the following property:

    properties["smsessionlocal"] = true;