C#>通用即插即用 - 收到COMException:在每用户订阅的所有者没有登录到指定的系统(从HRESULT异常:0x80040210)所有者、即用、即插、异常

2023-09-06 17:05:28 作者:丑的一比还颜控

我想使用一个C#.NET应用程序DLNA兼容设备,使用UPnP协议进行通信。我使用的是默认的Visual Studio中的UPnP库(通用即插即用1.0类型库(控制点))。我列出使用UPNPDeviceFinder.FindByType所有呈现设备。一切工作正常...

I'm trying to communicate with dlna compliant devices using a C#.net application, using the UPnP protocol. I'm using the default Visual studio UPnP library("UPnP 1.0 type library (control point)"). I list all rendering devices using UPNPDeviceFinder.FindByType. All works fine...

现在使用的功能我得到的AVTransport服务:

Now I get the AVTransport service using the function:

    public UPnPService GetAVTransport(UPnPDevice mediaDevice)
    {
        foreach (UPnPService service in mediaDevice.Services)
        {
            Debug.Print(service.ServiceTypeIdentifier);
            if (service.ServiceTypeIdentifier == "urn:schemas-upnp-org:service:AVTransport:1")
            {
                return service;
            }
        }

        return null;
    }

我试图发送一个播放命令的设备,像这样:

I try to send a play command to a device like so:

    Service = GetAVTransport(Device);

    object[] input = new object[2]
    {
        "0", // Object Id
        "1" //  Speed
    };

    object output = new object();

    Service.InvokeAction("Play", input, ref output);

在最后一行,我得到以下错误:

On the last line, i get the following error:

收到COMException:没有登录到指定的系统中的每用户订阅的所有者(从HRESULT异常:0x80040210)

COMException: The owner of the PerUser subscription is not logged on to the system specified (Exception from HRESULT: 0x80040210)

这是什么意思。这是完全不清楚为什么这种异常发生。

What does this mean. It's totally unclear as to why this exception occurs.

谢谢,  托马斯

推荐答案

COM尝试是有益的,提供最近的已知的文本消息,但它让你感到困惑吧。问题是,你的HRESULT设施code是004,这意味着FACILITY_ITF这意味着任何COM接口方法。作为微软 COM错误code DOC :

COM tried to be helpful by providing the nearest known textual message, but it confused you instead. The problem is that your HRESULT facility code is 004, which means FACILITY_ITF which means ANY COM interface method. As said explicitly in the Microsoft COM error code doc:

2的HRESULT使用完全相同的32位值从两个返回   不同的接口可能有不同的含义。

two HRESULTs with exactly the same 32-bit value returned from two different interfaces might have different meanings

code 210意味着每个接口的不同的东西。 COM已经选择 EVENT_E_PER_USER_SID_NOT_LOGGED_ON 这是不涉及到的UPnP的。它应该告诉你只是code,或者是足够聪明的知道,在UPnP的意思的 UPNP_E_ACTION_REQUEST_FAILED 。我已经找到了code。在 UPnP.h 从Windows C ++ SDK的映射,说不上其中C#查找它。对于任何进一步的COM异常,忽略文本,并只查找code在特定于你刚才叫的UPnP方法错误列表。同样,相同的code可能有一点不同的含义在不同的UPnP方法的范围。

Code 210 means different things per interface. COM has selected EVENT_E_PER_USER_SID_NOT_LOGGED_ON which is not related to UPnP at all. It should have told you just the code, or be clever enough to know that in UPnP it means UPNP_E_ACTION_REQUEST_FAILED. I have found out the code mapping in UPnP.h from Windows C++ SDK, dunno where C# looks for it. With any further COM exceptions, ignore the text and just look up the code in the list of errors specific for the UPnP method you just called. Again the same code might have little bit different meaning in scope of different UPnP methods.

现在关于为何请求已失败在设备上的原因。我敢打赌,你也没有告诉任何 SetAVTransport 的行动,因此该设备根本不知道玩什么,它的 TransportState 的是NO_MEDIA。如果你不喜欢学习但如何正确使用 AVTransport 服务,只是想看看你的MediaRenderer做一些神奇,尽量 RenderingControl 服务。操作 SetMute SetVolume 应该是有肯定的,设置RGB水平,也很有趣,但可能不被特定的提供渲染设备。

Now on to the reason why the request has failed on the device. I bet you didn't call any SetAVTransport action, so the device simply doesn't know what to play and it's TransportState is NO_MEDIA. If you don't feel like studying yet how to use AVTransport service correctly and just want to see your MediaRenderer doing something magically, try RenderingControl service. Actions SetMute and SetVolume should be there for sure, setting RGB levels is fun too but may not be provided by your particular renderer device.

如果有疑问,可以使用的强大DeviceSpy 英特尔开发者工具的。

When in doubt, use the mighty DeviceSpy of Intel Developer Tools.