gpt4 book ai didi

连接到示例 DBus 守护进程的 C# 程序总是得到 'Access is denied: DBus.BusObject'

转载 作者:行者123 更新时间:2023-11-30 12:48:34 35 4
gpt4 key购买 nike

对于我们当前的项目,我们使用 DBus (1.6.n)。它主要在共享内存模式下从 C++ 访问,而且效果非常好。

我现在正尝试从 C# 程序访问同一个 DBus。

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

每当我建立连接时,守护程序控制台都会显示我正在与它通信,但只要我尝试访问连接上的任何方法,我就会收到错误消息;

'访问被拒绝: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();
}

注释的代码最终也会产生相同的错误。

我已经逐步完成了调试器,它总是在 TypeImplementer.cs 中得到以下代码;

公共(public)类型 GetImplementation(类型 declType) { 输入 ret;

        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;
}

我还没有找到任何关于从 C# 访问 DBus 的有用示例或文档,而且似乎最近几乎没有任何关于此的条目,所以可能没有其他人在尝试这个。

我在与测试程序相同的文件夹中运行守护程序。当我在 Windows 上运行时,守护进程正在监听 tcp 设置;

string addr = "tcp:host=localhost,port=12345";

由于这是下载中包含的示例,我认为它会非常简单,但可惜还没有运气。

还有其他人来过这里并知道下一 block 拼图吗?

如有任何想法,我们将不胜感激。

最佳答案

由于没有收到任何评论或回复,我将使用提问后找到的信息来回答问题。

DBus 似乎没有有用的 C# 接口(interface)。 (有用的,我的意思是一个有用的!)我能找到的唯一信息或示例不是最新的,而且似乎没有人在提供工作界面上付出任何努力。

我已决定使用作为 Windows 服务编写的 C++ 实现与 DBus 交互,我的 C# 程序将通过该服务向 DBus 发送消息。这似乎工作正常,因此满足业务需求。

我很失望不能让 C# 到 DBus 工作,但是有很多服务总线实现可以在 Windows 上工作,所以将来我会考虑实现这些而不是 DBus。

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

关于连接到示例 DBus 守护进程的 C# 程序总是得到 'Access is denied: DBus.BusObject',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13766100/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com