PeerNameResolver.Resolve Method (PeerName)


Resolves the specified PeerName in all clouds known to the calling peer.

Namespace:   System.Net.PeerToPeer
Assembly:  System.Net (in System.Net.dll)

public PeerNameRecordCollection Resolve(
	PeerName peerName


Type: System.Net.PeerToPeer.PeerName

The PeerName to resolve.

Return Value

Type: System.Net.PeerToPeer.PeerNameRecordCollection

A PeerNameRecordCollection that contains all peer name records (represented as PeerNameRecord objects) associated with the specified peer name. For unsecured peer names, the same PeerName can be registered by different users in the same Cloud, and associated with different endpoints.

Exception Condition

The peerName parameter is set to null.


The peer name specified cannot be resolved.

This method associates a peer name to clouds. All clouds are queried for the PeerName. If the peer name cannot be resolved or is null, an PeerToPeerException is thrown.

For unsecured peer names, the same name can be registered (and associated with different endpoints) by different peers within the same cloud.

Calling the PeerNameResolver method is similar to calling the Resolve method for each peer name record in the PeerNameRecordCollection. Note that using the Resolve method on an individual peer name record does not invalidate resolving multiple peer names.

For every Resolve method, there is an equivalent ResolveAsync method. Their parameter lists are identical, except that the ResolveAsync method includes a system token for asynchronous event handling.

If the Cloud parameter is not supplied, the method uses the Available shortcut to fill in cloud parameters.

The ResolveCompleted event will be raised if the resolve operation completes in error or is canceled.

The following code example illustrates how to resolve a PeerName published in any Cloud.

static void Main(string[] args)

        if (args.Length != 1)
            Console.WriteLine("Usage: PeerNameResolver.exe <PeerNameToResolve>");

        // create a resolver object to resolve a Peer Name that was previously published
        PeerNameResolver resolver = new PeerNameResolver();
        // The Peer Name to resolve must be passed as the first 
        // command line argument to the application
        PeerName peerName = new PeerName(args[0]);
        // Resolve the Peer Name 
        // This is a network operation and will block until the resolve completes
        PeerNameRecordCollection results = resolver.Resolve(peerName);

        // Display the data returned by the resolve operation
        Console.WriteLine("Resolve operation complete.\n", peerName);
        Console.WriteLine("Results for PeerName: {0}", peerName);

        int count = 1;
        foreach (PeerNameRecord record in results)
            Console.WriteLine("Record #{0} results...", count);

            if (record.Comment != null)

            if (record.Data != null)
                // Assumes the data blob associated with the PeerName 
                // is made up of ASCII characters

            foreach (IPEndPoint endpoint in record.EndPointCollection)
                Console.WriteLine("\t Endpoint:{0}", endpoint);


    catch (Exception e)
        Console.WriteLine("Error occured while attempting to resolve the PeerName: {0}", e.Message);

        // P2P is not supported on Windows Server 2003
        if (e.InnerException != null)
            Console.WriteLine("Inner Exception is {0}", e.InnerException);

.NET Framework
Available since 3.5
Return to top