See the question and my original answer on StackOverflow

Once you've done the midl + tlbimp, you can just write this kind of code, as the tlbimp should have create a class (UPnPRegistrarClass) and an interface IUPnPRegistrar that the underlying COM class implements:

IUPnPRegistrar registrar = (IUPnPRegistrar)new UPnPRegistrarClass();
registrar.RegisterDevice(
    File.ReadAllText("DimmerDevice-Desc.xml"),
    "My.Class",
    "MyInitString",
    "MyContainerId",
    Path.GetFullPath("."),
    3200);

Note: for this to work, download the UPnP device registration sample on your disk, and copy the two XML description files to the current execution path. You also must implement a COM Object with a progid ("My.Class" that works because the RegisterDevice call will indeed instantiate this object to build an identifier. You can do that with .NET.

Device and service description formats are available here: UPnP™ Device Architecture 1.1. In the Windows world, there are some extra restrictions specified here: Creating a Device Description (Windows)