none
Register a device on UPnP with C# using the Device Host API : Value does not fall within the expected range.

    Question

  • Hi,

    I'm trying to use the MS Device Host API, to register a device.

    I've imported the COM component(the host one), and have the following code:

    //Main code

    IUPnPRegistrar registrar = (IUPnPRegistrar)new UPnPRegistrarClass(); String description = GetDescription(); String path = GetPath(); string registerDevice = registrar.RegisterDevice(description, "UPnPHosterTester.DeviceControl", "Init", "Container", path, 1800);

    //sub methods

    private string GetPath()
    {
    return Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    }

    private string GetDescription()
    {
    string xml = File.OpenText("DeviceDescription.xml").ReadToEnd();
    xml = xml.Replace("@@UDN@@", "uuid:" +Guid.NewGuid().ToString());
    return xml;
    }

    It read an xml file:

    <?xml version="1.0" encoding="utf-8" ?>
    <root xmlns="urn:schemas-upnp-org:device-1-0">
    	<specVersion>
    		<major>1</major>
    		<minor>1</minor>
    	</specVersion>
    	<device>
    		<UDN>@@UDN@@</UDN>
    		<friendlyName>Test device</friendlyName>
    		<deviceType>urn:test-com:device:HostDevice:1</deviceType>
    		<manufacturer>Test</manufacturer>
    		<modelName>Test model name</modelName>
    	</device>
    </root>

    My problem is that when I try to register it, I got this error: 

    System.ArgumentException was unhandled
      Message=Value does not fall within the expected range.
      Source=UPnPHostLib
      StackTrace:
           at UPnPHostLib.IUPnPRegistrar.RegisterDevice(String bstrXMLDesc, String bstrProgIDDeviceControlClass, String bstrInitString, String bstrContainerId, String bstrResourcePath, Int32 nLifeTime)
           at UPnPHosterTester.Hoster.Start() in E:\Dev\Discovery\XMS_SW_Discovery_B\Solution\UPnPHosterTester\Hoster.cs:line 32
           at UPnPHosterTester.Program.Main(String[] args) in E:\Dev\Discovery\XMS_SW_Discovery_B\Solution\UPnPHosterTester\Program.cs:line 19
           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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: 
    

    I'm searching what I'm doing wrong since two days, and I don't find any example code for c#. This exception isn't very explicit(and the 1800 is in the range).

    So what could have I done wrong?

    Wednesday, February 06, 2013 2:42 PM