title: Could not iterate UPNP services of a device using microsoft UPNP.DLL (C#, Visual Studio 2010)
body: <p>Hi Stack Overflow and sorry for my non-native English level</p>
  
  <p>Currently programming an UPnP discovery service for a project in C# using .NET 4.0 on Visual Studio 2010.</p>
  
  <p>I'm using the official Microsoft UPnP COM API and it's my first time using UPnP. My problem is that I'm trying to iterate on the services of the devices discovered by the library and a COM HRESUT:0X80040500 exception is thrown.</p>
  
  <p>Here is a sample of my code:</p>
  
  <pre><code>IList&lt;UpnpDevice&gt; result = new List&lt;UpnpDevice&gt;();
  
  UPnPDevices upnpDiscoveryResult = m_UPnPFinder.FindByType(upnpType, 0);
  
  var upnpDiscoveryResultEnumerator = upnpDiscoveryResult.GetEnumerator();
  
  while (upnpDiscoveryResultEnumerator.MoveNext())
  {
      var upnpDiscoveryDevice = (IUPnPDevice)upnpDiscoveryResultEnumerator.Current;
  
      UPnPServices services = upnpDiscoveryDevice.Services;
      var allServices = services.GetEnumerator();
  
      // ------ Exception is thrown just below
      while (allServices.MoveNext())
      {
          UPnPService service = allServices.Current as UPnPService;
          if (service.Id == "urn:schemas-upnp-org:service:WANIPConnection:1")
          {
          }
          else if (service.Id == "urn:schemas-upnp-org:service:WANPPPConnection:1")
          {
          }
      }
  </code></pre>
  
  <p>I am lost on what to do. </p>
  
  <p>According to these people which I think I may be having the same error... </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/13783680/how-do-i-access-services-of-upnp-device">How do I access services of UPnP device?</a></li>
  <li><a href="http://social.msdn.microsoft.com/Forums/en-US/b16a1e3b-9e85-480a-8240-82a2af73b924/could-not-iterate-upnp-services-of-a-device-using-microsoft-upnpdll" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en-US/b16a1e3b-9e85-480a-8240-82a2af73b924/could-not-iterate-upnp-services-of-a-device-using-microsoft-upnpdll</a>)</li>
  </ul>
  
  <p>...the problem may come from the official DLL and I guess I should better use a new one, but I wanted to ask here first. It seems weird to me that such an obvious bug could indeed come from the API.</p>