普通用户在 openSUSE 下运行 KeePass 报错

请教一下各位,

原来在 Fedora 17 KDE 下, 使用 mono 执行 KeePass; 现在系统换 openSUSE 了, 普通用户不能正常运行 KeePass, 但是 root 用户却可以正常运行, Google 很久报错信息, 也没有找到解决办法, 求破!

已安装 mono 相关的 rpm 包如下:

> rpm -qa | grep mono
mono-core-3.0.4-1.4.1.x86_64
mono-data-oracle-3.0.4-1.4.1.x86_64
mono-devel-3.0.4-1.4.1.x86_64
mono-nunit-3.0.4-1.4.1.x86_64
mono-wcf-3.0.4-1.4.1.x86_64
libmonosgen-2_0-devel-3.0.4-1.4.1.x86_64
monodoc-core-3.0.4-1.4.1.x86_64
mono-reactive-3.0.4-1.4.1.x86_64
mono-data-postgresql-3.0.4-1.4.1.x86_64
mono-extras-3.0.4-1.4.1.x86_64
mono-complete-3.0.4-1.4.1.x86_64
libmono-2_0-1-3.0.4-1.4.1.x86_64
mono-winfxcore-3.0.4-1.4.1.x86_64
mono-mvc-3.0.4-1.4.1.x86_64
mono-locale-extras-3.0.4-1.4.1.x86_64
mono-web-3.0.4-1.4.1.x86_64
mono-data-3.0.4-1.4.1.x86_64
mono-winforms-3.0.4-1.4.1.x86_64
libmono-2_0-devel-3.0.4-1.4.1.x86_64
mono-data-sqlite-3.0.4-1.4.1.x86_64
libmonosgen-2_0-0-3.0.4-1.4.1.x86_64
mono-entityframework-3.0.4-1.4.1.x86_64

报错信息如下:

> mono /usr/lib/keepass/KeePass.exe 

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: key
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetObject (System.String name, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetObject (System.String name) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.KeyboardLayouts.LoadLayouts () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.KeyboardLayouts.get_Layouts () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard.DetectLayout (System.Windows.Forms.KeyboardLayouts layouts) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard.EnsureLayoutInitialized () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard..ctor (IntPtr display, IntPtr clientWindow) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: key
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetObject (System.String name, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Resources.ResourceManager.GetObject (System.String name) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.KeyboardLayouts.LoadLayouts () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.KeyboardLayouts.get_Layouts () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard.DetectLayout (System.Windows.Forms.KeyboardLayouts layouts) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard.EnsureLayoutInitialized () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.X11Keyboard..ctor (IntPtr display, IntPtr clientWindow) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String] args) [0x00000] in <filename unknown>:0

普通用户用 sudo 执行 KeePass 的报错:

> sudo mono /usr/lib/keepass/KeePass.exe 

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String] args) [0x00000] in <filename unknown>:0

但是 DISPLAY 变量是没有问题的, 和 root 用户的一样:

> echo $DISPLAY
:0

初步猜测可能是 openSUSE 的配置不当导致这个报错, 因为 root 可以正常执行, 不太可能是 mono 或者 KeePass 有问题.

这你可错了,mono 就是 novell 开发的,我们的 mono 不可能有错,只能有 keepass 没跟上我们源里的 mono 版本这种错误。

export MONO_LOG_LEVEL=debug
mono /usr/lib/keepass/KeePass.exe >> $HOME/keepass_log.txt

可以开 debug 输出的。

我测试了源里的 2.21,自己也编译了 2.22,都是这个错误。

你可以拿附件里的 log 去 keepass 官方报 bug 了。mono 这东西就是在 Linux 下写 windows C,你得找 Windows 程序员才能看明白。

另外你那个 sudo 的错误,建议你去找找 X Display 相关的知识,root 登录的 Displey 和普通用户登录然后 sudo 或 su 的 Display 不是一个。就跟你 sudo kwrite 和 root 登录用 kwrite 一个道理。
keepass.log (81.7 KB)

多谢苏姐!

之前因为 SF.net 被墙, 我在Chrome的 SwitchySharp 里加规则走GAE 了, 导致我注册用户的一直报 `your registration violated our anti spam filter’, 反复试了好几个邮箱和用户名都没解决这个问题, 后来想起来在维基百科遇到过GAE 的IP 不能编辑的问题, 今天把SwitchySharp 的规则改了一下, 终于成功注册了用户, 提交了 Bug .
希望老外能看懂我那很鹾的英语…

你的SwitchySharp 的规则是怎么改的?
我通过G0A*?gent无法从sourceforge上下东西

办公室的电脑开始是走 GAE 的, 注册用户的时候改成 直接连接 ] 了.
刚才用家里的电脑从 SF.net 下载了文件, 不走代理直接连就可以了, 家里用的 SwitchySharp 的切换规则里压根就没有 SF.net 的, XD
我这里是上海长城宽带的线路, 你不走代理直连试试看.

报告女皇大人, 这个Bug 被Close 了, 原因如下 (原文请 移步](https://sourceforge.net/p/keepass/bugs/1121/#5e5e) ):

女皇能否和mono 开发人员确认一下, 到底是哪个有问题?

mono 的 bugzilla 就是 bugzilla.novell.com,所以你去我们自己的 bugzilla 把你在 keepass 报的东西搬过来,你就能接触到 mono 的开发人员了。

另外我看了下 debian/ubuntu 的 mono,它们不够新,用的是 2.10,openSUSE 12.3 里是 3.0.4。

说真的我还真不认为这是 mono 的 bug,因为很简单,你 root 没出错啊。估摸着是 keepass 的开发者用错 API 或者没在 3.0.X 上测试过造成的,但没办法,要打脸你总归要找到夯实的证据。所以你还是去我们自己的 bugzilla 叫帮手吧。