连接到示例DBus守护进程的C#程序总是得到';访问被拒绝:DBus.BusObject';

连接到示例DBus守护进程的C#程序总是得到';访问被拒绝:DBus.BusObject';,c#,dbus,C#,Dbus,对于我们当前的项目,我们使用DBus(1.6.n)。 在共享内存模式下,它主要是从C++访问的,并且工作得很好。 我现在正试图从C#程序访问相同的DBU 为了先尝试一下,我下载了我能找到的最新版本的dbus sharp,并启动了下载中包含的守护进程,看看是否可以从我的测试C#app连接到它 每当我建立连接时,守护进程控制台都会显示我正在与它通信,但一旦我尝试访问连接上的任何方法,就会出现错误 '访问被拒绝:DBus.BusObject' 这是我尝试过的代码 DBus.Bus dB

对于我们当前的项目,我们使用DBus(1.6.n)。 在共享内存模式下,它主要是从C++访问的,并且工作得很好。 我现在正试图从C#程序访问相同的DBU

为了先尝试一下,我下载了我能找到的最新版本的dbus sharp,并启动了下载中包含的守护进程,看看是否可以从我的测试C#app连接到它

每当我建立连接时,守护进程控制台都会显示我正在与它通信,但一旦我尝试访问连接上的任何方法,就会出现错误

'访问被拒绝:DBus.BusObject'

这是我尝试过的代码

        DBus.Bus dBus = null;
        try
        {
            //input address comes from the UI and ends up as "tcp:host=localhost,port=12345";
            //dBus = new Bus(InputAddress.Text + inputAddressExtension.Text);
            //string s = dBus.GetId();
            //dBus.Close();

            //DBus.Bus bus = DBus.Bus.System;
            //DBus.Bus bus = Bus.Open(InputAddress.Text + inputAddressExtension.Text);
            //DBus.Bus bus = DBus.Bus.Session;
            //DBus.Bus bus = DBus.Bus.Starter;

            var conn = Connection.Open(InputAddress.Text + inputAddressExtension.Text);
            var bus = conn.GetObject<Introspectable>(@"org.freedesktop.DBus.Introspectable", new ObjectPath("/org/freedesktop/DBus/Introspectable"));

            bus.Introspect();

        }
        finally
        {
            if(dBus != null)
                dBus.Close();
        }
DBus.Bus DBus=null;
尝试
{
//输入地址来自UI,最终为“tcp:host=localhost,port=12345”;
//dBus=新总线(InputAddress.Text+inputAddressExtension.Text);
//字符串s=dBus.GetId();
//dBus.Close();
//DBus.Bus Bus=DBus.Bus.System;
//DBus.Bus Bus=Bus.Open(InputAddress.Text+inputAddressExtension.Text);
//DBus.Bus-Bus=DBus.Bus.Session;
//DBus.Bus Bus=DBus.Bus.Starter;
var conn=Connection.Open(InputAddress.Text+inputAddressExtension.Text);
var bus=conn.GetObject(@“org.freedesktop.DBus.Introspectable”,新对象路径(“/org/freedesktop/DBus/Introspectable”);
内省();
}
最后
{
if(dBus!=null)
dBus.Close();
}
注释后的代码最终也会产生相同的错误

我已经使用了调试器,它总是在TypeImplementer.cs中找到以下代码

公共类型GetImplementation(类型declType) { retT型

        lock (getImplLock)
            if (map.TryGetValue (declType, out retT))
                return retT;

        string proxyName = declType.FullName + "Proxy";

        Type parentType;

        if (declType.IsInterface)
            parentType = typeof (BusObject);
        else
            parentType = declType;

        TypeBuilder typeB = modB.DefineType (proxyName, TypeAttributes.Class | TypeAttributes.Public, parentType);

        if (declType.IsInterface)
            Implement (typeB, declType);

        foreach (Type iface in declType.GetInterfaces ())
            Implement (typeB, iface);

        retT = typeB.CreateType (); <======== Fails here ==========

        lock (getImplLock)
            map[declType] = retT;

        return retT;
    }
lock(getimplock)
if(map.TryGetValue(declType,out-retT))
返回retT;
字符串proxyName=declType.FullName+“Proxy”;
类型parentType;
if(declType.IsInterface)
parentType=typeof(总线对象);
其他的
parentType=declType;
TypeBuilder typeB=modB.DefineType(proxyName,TypeAttributes.Class | TypeAttributes.Public,parentType);
if(declType.IsInterface)
机具(B型、declType型);
foreach(在declType.GetInterfaces()中键入iface)
实施(B型,iface);

retT=typeB.CreateType();由于没有收到任何评论或回复,我将用提问后发现的信息回答这个问题

DBus似乎没有有用的C#接口 我能找到的唯一信息或示例不是最新的,似乎没有在提供工作界面上花费任何精力

我决定用一个C++实现,作为一个Windows服务与DBUS接口,我的C程序将通过服务发送消息给DBUS,这似乎是可行的,因此满足业务需求。 我很失望不能让C#to DBus工作,但是有很多服务总线实现可以在Windows上工作,所以在未来我将考虑实现这些服务总线而不是DBus


如果有人真的提出了一个可行的、有文档记录的解决方案来从Windows上的C#访问DBus,我仍然有兴趣看到它。

当我创建新的测试项目并将DBus cs源文件添加到主项目程序集中时,我也遇到了同样的错误。那是在动态创建的程序集中动态创建IBusProxy类型时

asmB = AppDomain.CurrentDomain.DefineDynamicAssembly (new AssemblyName ("NDesk.DBus.Proxies"), canSave ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run);
modB = asmB.DefineDynamicModule ("NDesk.DBus.Proxies");
......
retT = typeB.CreateType ();

我认为这是因为当前正在运行的程序集对已创建的程序集不友好。就在我添加到项目编译的NDesk.DBus.dll时,此错误消失了。

Update-我已尝试根据“文档”在与扩展名为.conf的exe同名的配置文件中添加各种设置!守护进程似乎没有注意到对于这些设置中的任何一个,我可以输入任何我喜欢的内容,并且守护进程的运行与以前完全相同。