LocalMessageReceiver Constructor (String, ReceiverNameScope, IEnumerable<String>)


Initializes a new instance of the LocalMessageReceiver class and configures it with the specified name, namescope requirement, and allowed sender domains.

Namespace:  System.Windows.Messaging
Assembly:  System.Windows (in System.Windows.dll)

public LocalMessageReceiver(
	string receiverName,
	ReceiverNameScope nameScope,
	IEnumerable<string> allowedSenderDomains


Type: System.String
The name of the receiver, which must be unique either within the global namescope or the receiver's domain, depending on the value of the nameScope parameter.
Type: System.Windows.Messaging.ReceiverNameScope
A value that indicates whether the receiverName is scoped to the global namescope or to the receiver's specific domain.
Type: System.Collections.Generic.IEnumerable<String>
The domains that the receiver can receive messages from, or AnyDomain to receive from any domain.


receiverName is null.


allowedSenderDomains is null.


allowedSenderDomains contains one or more null entries.


receiverName is longer than 256 characters.


allowedSenderDomains contains one or more entries longer than 256 characters.


allowedSenderDomains contains one or more entries with invalid characters ("," and ":").

This constructor enables you to initialize the ReceiverName, NameScope, and AllowedSenderDomains properties.

For more information, see Communication Between Local Silverlight-Based Applications.

The following code example demonstrates how to use this constructor. This example is part of a larger example available in How to: Implement Communication Between Local Silverlight-Based Applications.

using System;
using System.Windows.Controls;
using System.Windows.Messaging;

namespace ReceivingApplication
    public partial class Receiver : UserControl
        public Receiver()

            LocalMessageReceiver messageReceiver =
                new LocalMessageReceiver("receiver",
                ReceiverNameScope.Global, LocalMessageReceiver.AnyDomain);
            messageReceiver.MessageReceived += messageReceiver_MessageReceived;
            catch (ListenFailedException)
                output.Text = "Cannot receive messages." + Environment.NewLine +
                    "There is already a receiver with the name 'receiver'.";

        private void messageReceiver_MessageReceived(
            object sender, MessageReceivedEventArgs e)
            e.Response = "response to " + e.Message;
            output.Text =
                "Message: " + e.Message + Environment.NewLine +
                "NameScope: " + e.NameScope + Environment.NewLine +
                "ReceiverName: " + e.ReceiverName + Environment.NewLine +
                "SenderDomain: " + e.SenderDomain + Environment.NewLine +
                "Response: " + e.Response;


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions