1

我们正在尝试使用以下示例代码通过 .Net 代码使用 Windows PNM API:

using System;
using System.Net.PeerToPeer;
using System.Net.PeerToPeer.Collaboration;

namespace GetPeersNearMe
{
    class Program
    {
        static void Main(string[] args)
        {            
            PeerCollaboration.SignIn(PeerScope.All);

            PeerNearMeCollection peers = null;
            try
            {
                peers = PeerCollaboration.GetPeersNearMe();
                if (peers == null ||
                    peers.Count == 0)
                {
                    Console.WriteLine("There are no peers near me.");
                }
                foreach (PeerNearMe pnm in peers)
                {
                    Console.WriteLine("Getting the peers near me: {0}, nickname {1}, isOnline {2}",
                        pnm.ToString(),
                        pnm.Nickname,
                        pnm.IsOnline);
                }
            }
            catch (PeerToPeerException p2pEx)
            {
                Console.WriteLine("Could not obtain an enumeration of the peers near me: {0}", p2pEx.Message);
            }
            catch (InvalidOperationException ioEx)
            {
                Console.WriteLine("The application is no longer signed into the Peer Collaboration Infrastructure: {0}",
                    ioEx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected exception caught when trying to enumerate the peers near me: {0}",
                    ex.Message);
            }

        }
    }

我们不断收到以下异常:

System.Net.PeerToPeer.PeerToPeerException was unhandled
  HResult=-2146233088
  Message=Peer collaboration startup failed.
  Source=System.Net
  StackTrace:
       at System.Net.PeerToPeer.Collaboration.CollaborationHelperFunctions.Initialize()
       at System.Net.PeerToPeer.Collaboration.PeerCollaboration.SignIn(PeerScope peerScope)
       at GetPeersNearMe.Program.Main(String[] args) in c:\Program.cs:line 11
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ComponentModel.Win32Exception
       HResult=-2147467259
       Message=The Windows Peer-to-Peer infrastructure is not licensed to operate on this platform.
       ErrorCode=-2147467259
       NativeErrorCode=-2140995580
       InnerException:

在测试我们的代码之前,我们确保以下 Windows 服务正在运行:

  • 对等名称解析协议
  • 对等网络分组
  • 对等网络身份管理器
  • PNRP 机器名称发布服务

我们仍然得到上述异常。我们缺少什么?

我们在 Windows 10 机器上运行代码,并且代码使用 .Net 4.5.1 运行

4

0 回答 0