模拟用户时出现IOException

时间:2014-11-26 21:25:33

标签: c# wpf tabcontrol impersonation

当我在WPF应用程序中模拟用户时,我收到一个非常奇怪的错误。

我的应用程序基本上是一个带有两个选项卡的Window中的TabControl。在一个选项卡上,启动时显示的那个,我有一个图表。在另一个选项卡上,我有一些用于设置图形的控件。特别是,我有两个ListView控件(或其派生)。在MenuBar中,我有一个用户用来以不同的用户身份登录的MenuItem,我正在使用WindowsImpersonation。

问题出现了:如果我启动程序,那么,在点击任何其他内容之前,我点击Login菜单项并成功登录,然后我点击第二个标签,我得到一个IOException并显示消息“目录名称是无效的”。这是调用堆栈的顶部:

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.Path.InternalGetTempFileName(Boolean checkHost)
at System.IO.Path.GetTempFileName()
at System.Windows.Input.Cursor.LoadFromStream(Stream cursorStream)
at System.Windows.Input.Cursor..ctor(Stream cursorStream)
at System.Windows.Controls.GridViewColumnHeader.GetCursor(Int32 cursorID)
at System.Windows.Controls.GridViewColumnHeader.get_SplitCursor()
at System.Windows.Controls.GridViewColumnHeader.HookupGripperEvents()
at System.Windows.Controls.GridViewColumnHeader.OnApplyTemplate()
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.GridViewHeaderRowPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
...
(The rest of the stack is a bunch of Measure methods and Event handlers up until I get to the Threading and Application methods.)

看起来程序无法找到包含GridViewColumnHeader的光标信息的文件。注意:我没有使用任何类型的特殊光标,只是标准的Windows光标;虽然我确实有事件附加到GridViewColumnHeader。

如果我首先单击第二个选项卡,然后单击登录,则不会抛出此错误,如果单击第二个选项卡,请单击第一个选项卡上的,然后登录。因此,我与渲染引擎进行通信的方式显然有问题。

在我的互联网搜索中,我只遇到另外一个人遇到类似这样的事情:https://social.msdn.microsoft.com/Forums/en-US/7fb648b6-2e4f-47da-91fd-a6fefd7e5462/impersonate-in-wpf-c-throws-the-directory-name-is-invalid-exception?forum=csharpgeneral,而且问题没有真正的答案。

我确信我可以通过“选择”代码隐藏中的第二个选项卡并重新选择第一个选项卡来解决这个问题。但是,我更愿意处理这个问题,而不是过于苛刻。

有任何建议或见解吗?感谢。

0 个答案:

没有答案