Changing the month of a DatePicker throws this exception:
更改DatePicker的月份会抛出这个异常:
System.Windows.Automation.ElementNotAvailableException: 'Element does not exist or it is virtualized; use VirtualizedItem Pattern if it is supported.'
System.Windows.Automation。ElementNotAvailableException: '元素不存在或被虚拟化;如果支持,请使用VirtualizedItem模式。
The Stack Trace:
堆栈跟踪:
at MS.Internal.Automation.ElementUtil.Invoke(AutomationPeer peer, DispatcherOperationCallback work, Object arg) at MS.Internal.Automation.ElementProxy.GetPropertyValue(Int32 property)
在MS.Internal.Automation.ElementUtil。调用(AutomationPeer, DispatcherOperationCallback工作,对象arg)。GetPropertyValue(Int32属性)
I created a simple project with only one DatePicker on the main window and it gives the same exception.
我创建了一个简单的项目,主窗口上只有一个DatePicker,它会给出相同的异常。
<DatePicker x:Name="datePicker1" Width="150" />
.NET Framework version: 4.6
net Framework版本:4.6
I found the same problem in a 6 years old question, but no answer till now!
我在一个6岁的问题中发现了同样的问题,但是到现在还没有答案!
Edit:
编辑:
I tried different .NET Framework versions: 4.5, 4.6.1, and the problem still the same.
我尝试了不同的。net框架版本:4.5,4.6.1,但是问题还是一样的。
5 个解决方案
#1
4
The exception appears to depend on the Tablet PC Input Service being enabled. If I had to guess, the error occurs in UI Automation code that only runs when pen-based input is available (and possibly touch-based input). I've seen that service induce undesirable side effects in WPF applications before, and most of those issues were also related to UI Automation.
例外情况似乎取决于是否启用了平板电脑输入服务。如果我不得不猜测,错误发生在UI自动化代码中,该代码只在基于笔的输入可用(可能还有基于触摸的输入)时运行。我以前见过服务在WPF应用程序中产生不良的副作用,其中大多数问题也与UI自动化有关。
Since this appears to be a "first chance" exception (it gets handled somewhere in the framework), the only people who should notice are developers who have their IDE configured to break on all exceptions (as opposed to only unhandled exceptions). If that is indeed the case, and if those developers are not actually using the pen or touch input capabilities, it might be easiest to just disable the Tablet PC Input Service and move on with your lives.
由于这似乎是一个“第一次机会”异常(它在框架中的某个地方被处理),惟一应该注意的是开发人员,他们的IDE被配置为对所有异常进行中断(而不是只处理未处理的异常)。如果确实如此,而且这些开发人员实际上没有使用笔或触控输入功能,那么可能最简单的方法就是禁用平板电脑输入服务,然后继续你的生活。
Alternatively, you could configure Visual Studio to not break on that particular exception type, which only pertains to UI Automation anyway.
或者,您可以配置Visual Studio,使其不会中断特定的异常类型,这只与UI自动化有关。
Since things are pretty slow at the office this week, I will spend some additional time looking into this. If I can find a code-based solution, I will update my answer here. But from the look of it, the UI is constructed almost entirely programmatically, so this probably isn't something you can fix with a simple custom template.
由于本周办公室的工作进展非常缓慢,我将花一些额外的时间来研究这个问题。如果我能找到基于代码的解决方案,我将在这里更新我的答案。但是从它的外观来看,UI几乎是完全以编程的方式构造的,所以这可能不是您可以通过一个简单的自定义模板来修复的东西。
#2
3
If you look on the microsoft documentation it says:
如果你看一下微软的文档它说:
This exception can be raised if the element was in a dialog box that was closed, or an application that was closed or terminated.
如果元素在已关闭的对话框中,或者应用程序已关闭或终止,则可以引发此异常。
Could it be possible that you're closing the window on a "change month" event?
你是否有可能关闭一个“改变月”事件的窗口?
#3
3
It is difficult to reproduce your issue. The next suggestions may help you:
很难再现你的问题。下面的建议可能对你有所帮助:
-
another process may affect to your program. Do you use utilities like
Snoop
orUISpy
?另一个过程可能会影响到您的程序。你使用像Snoop或UISpy这样的工具吗?
-
your problem may be related to low-performance hardware or vendor software bug. See here answer for resolving this issue
您的问题可能与性能低下的硬件或供应商的软件缺陷有关。请看这里解决这个问题的答案。
-
your problem may be related to rendering a copy of UI-control which doesn't exist for some reasons. See this discussion for more details
您的问题可能与呈现ui控件的副本有关,因为某些原因它不存在。有关更多细节,请参见本讨论
#4
2
(As I needed some diversion) I tried to do some research on your case and could reproduce the mentioned exception. Enabling .NET Framework source stepping and anything else I could find I was able to pinpoint the exception to the Invoke
method of the ElementUtil
class in the PresentationCore.dll
. The corresponding code of the method looks like this:
(因为我需要转移一下注意力)我试着对你的案例做一些研究,并且可以重现上面提到的例外。在PresentationCore.dll中,启用。net Framework源代码步进和其他任何我能找到的功能,我能够确定ElementUtil类的调用方法的异常。方法对应的代码如下:
internal static object Invoke(AutomationPeer peer, DispatcherOperationCallback work, object arg)
{
Dispatcher dispatcher = peer.Dispatcher;
// Null dispatcher likely means the visual is in bad shape!
if( dispatcher == null )
{
throw new ElementNotAvailableException();
}
Exception remoteException = null;
bool completed = false;
object retVal = dispatcher.Invoke(
DispatcherPriority.Send,
TimeSpan.FromMinutes(3),
(DispatcherOperationCallback) delegate(object unused)
{
try
{
return work(arg);
}
catch(Exception e)
{
remoteException = e;
return null;
}
catch //for non-CLS Compliant exceptions
{
remoteException = null;
return null;
}
finally
{
completed = true;
}
},
null);
if(completed)
{
if(remoteException != null)
{
throw remoteException;
}
}
else
{
bool dispatcherInShutdown = dispatcher.HasShutdownStarted;
if(dispatcherInShutdown)
{
throw new InvalidOperationException(SR.Get(SRID.AutomationDispatcherShutdown));
}
else
{
throw new TimeoutException(SR.Get(SRID.AutomationTimeout));
}
}
return retVal;
}
Taking this code into consideration the (in my opinion) only possible reason is, that the specified dispatcher is null
. Altough I find the comment
考虑到这段代码(在我看来),唯一可能的原因是,指定的分派器是空的。尽管我找到了评论
// Null dispatcher likely means the visual is in bad shape!
//空调度器可能意味着视觉效果不佳!
funny, I have actually no idea why this is the case. I tired to debugging that fact but was unable to get any meaningful information. Only following stacktrace (which opened my eyes again about what is going on if we "just click a button"):
有趣的是,我不知道为什么会这样。我厌倦了调试这个事实,但却无法得到任何有意义的信息。只有遵循stacktrace(它再次睁开我的眼睛,告诉我如果我们“点击一个按钮”会发生什么):
PresentationCore.dll!MS.Internal.Automation.ElementUtil.Invoke(System.Windows.Automation.Peers.AutomationPeer peer, System.Windows.Threading.DispatcherOperationCallback work, object arg)
PresentationCore.dll!MS.Internal.Automation.ElementProxy.GetPropertyValue(int property)
[Native to Managed Transition]
UIAutomationCore.dll!ProviderCallouts::RawGetPropertyValue(struct IRawElementProviderSimple *,int,struct tagVARIANT *)
UIAutomationCore.dll!ProviderCallouts::GetPropertyValue(struct IRawElementProviderSimple *,unsigned short,class ProviderEntryPoint *,int,struct tagVARIANT *)
UIAutomationCore.dll!InProcClientAPIStub::GetPropertyValue(char *)
UIAutomationCore.dll!InProcClientAPIStub::InvokeInProcAPI(struct ITargetContextInvoker *,enum Protocol_MethodId,...)
UIAutomationCore.dll!AccessibleProxy::IsControl(struct IRawElementProviderFragment *,struct ITargetContextInvoker *)
UIAutomationCore.dll!AccessibleProxy::NormalizeUpwards(struct IRawElementProviderFragment *,struct ITargetContextInvoker *,struct IRawElementProviderFragment * *)
UIAutomationCore.dll![thunk]:EditProxy::Release`adjustor{32}' (void)
UIAutomationCore.dll!_UiaReturnRawElementProvider@16()
[Managed to Native Transition]
UIAutomationProvider.dll!MS.Internal.Automation.UiaCoreProviderApi.UiaReturnRawElementProvider(System.IntPtr hwnd = 0x000406ce, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, System.Windows.Automation.Provider.IRawElementProviderSimple el = {MS.Internal.Automation.ElementProxy})
UIAutomationProvider.dll!System.Windows.Automation.Provider.AutomationInteropProvider.ReturnRawElementProvider(System.IntPtr hwnd = 0x000406ce, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, System.Windows.Automation.Provider.IRawElementProviderSimple el = {MS.Internal.Automation.ElementProxy})
PresentationCore.dll!System.Windows.Interop.HwndTarget.CriticalHandleWMGetobject(System.IntPtr wparam, System.IntPtr lparam, System.Windows.Media.Visual root, System.IntPtr handle)
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, System.IntPtr wparam, System.IntPtr lparam)
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x0000003d, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x0000003d, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149)
[Native to Managed Transition]
user32.dll!__InternalCallWinProc@20()
user32.dll!InternalCallWinProc()
user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,void *,struct HWND__ *,enum _WM_VALUE,unsigned int,long,void *,int)
user32.dll!_DispatchClientMessage@24()
user32.dll!___fnDWORD@4()
ntdll.dll!_KiUserCallbackDispatcher@12()
user32.dll!_SendMessageTimeoutW@28()
oleacc.dll!NativeIAccessibleFromWindow(unsigned long,unsigned long,struct HWND__ *,unsigned long,struct _GUID const &,void * *)
oleacc.dll!_ORIGINAL_AccessibleObjectFromWindow@24()
oleacc.dll!_AccessibleObjectFromWindow@16()
oleacc.dll!_AccessibleObjectFromEvent@20()
oleacc.dll!_EXTERNAL_AccessibleObjectFromEvent@20()
msctf.dll!_AccessibleObjectFromEvent@20()
msctf.dll!CThreadInputMgr::OnAccFocusEvent()
msctf.dll!WinEventProc()
user32.dll!___ClientCallWinEventProc@4()
ntdll.dll!_KiUserCallbackDispatcher@12()
[Managed to Native Transition]
UIAutomationProvider.dll!MS.Internal.Automation.UiaCoreProviderApi.UiaRaiseAutomationEvent(System.Windows.Automation.Provider.IRawElementProviderSimple provider = {MS.Internal.Automation.ElementProxy}, int eventId = 0x00004e25)
UIAutomationProvider.dll!System.Windows.Automation.Provider.AutomationInteropProvider.RaiseAutomationEvent(System.Windows.Automation.AutomationEvent eventId = {System.Windows.Automation.AutomationEvent}, System.Windows.Automation.Provider.IRawElementProviderSimple provider = {MS.Internal.Automation.ElementProxy}, System.Windows.Automation.AutomationEventArgs e = {System.Windows.Automation.AutomationEventArgs})
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.RaiseAutomationEvent(System.Windows.Automation.Peers.AutomationEvents eventId)
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(System.Windows.IInputElement newFocus)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject focus, int timestamp)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element)
PresentationCore.dll!System.Windows.UIElement.Focus()
PresentationFramework.dll!System.Windows.Input.KeyboardNavigation.Navigate(System.Windows.DependencyObject currentElement, System.Windows.Input.TraversalRequest request, System.Windows.Input.ModifierKeys modifierKeys, System.Windows.DependencyObject firstElement)
PresentationFramework.dll!System.Windows.FrameworkElement.MoveFocus(System.Windows.Input.TraversalRequest request)
PresentationFramework.dll!System.Windows.Controls.Primitives.CalendarItem.FocusDate(System.DateTime date)
PresentationFramework.dll!System.Windows.Controls.Calendar.OnCalendarButtonPressed(System.Windows.Controls.Primitives.CalendarButton b, bool switchDisplayMode)
PresentationFramework.dll!System.Windows.Controls.Primitives.CalendarItem.Month_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Primitives.CalendarButton}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = true)
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Primitives.CalendarButton}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent)
PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Shapes.Rectangle}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false)
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Shapes.Rectangle}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted)
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 0x000406ce, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONUP, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066)
[Native to Managed Transition]
user32.dll!__InternalCallWinProc@20()
user32.dll!InternalCallWinProc()
user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,void *,struct HWND__ *,enum _WM_VALUE,unsigned int,long,void *,int)
user32.dll!_DispatchMessageWorker@8()
user32.dll!_DispatchMessageW@4()
WindowsBase.ni.dll!69d4936c()
[Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run()
WpfApp1.exe!WpfApp1.App.Main()
[Native to Managed Transition]
mscoreei.dll!__CorExeMain@0()
mscoree.dll!_ShellShim__CorExeMain@0()
mscoree.dll!__CorExeMain_Exported@0()
ntdll.dll!__RtlUserThreadStart()
ntdll.dll!__RtlUserThreadStart@8()
Just for fun here ist the same stacktrace as above in graphical form:
有趣的是,这里使用的是和上面一样的图形形式:
So my conslusion is that...
我的意思是……
- ...Mike Strobel's answer is the closest I've seen
- …迈克·斯特洛贝尔的回答是我见过的最接近的
- ...as of now I am curious myself
- …现在我自己也很好奇
#5
0
A possible work around would be to Try, Catch, Finally the UIAnimation exception and not raise any events (message boxes, error logs) when it occurs. Just let the code continue on as if nothing happened.
一个可能的工作是尝试,捕捉,最后是UIAnimation异常,当它发生时,不引发任何事件(消息框,错误日志)。让代码继续运行,就像什么都没发生一样。
#1
4
The exception appears to depend on the Tablet PC Input Service being enabled. If I had to guess, the error occurs in UI Automation code that only runs when pen-based input is available (and possibly touch-based input). I've seen that service induce undesirable side effects in WPF applications before, and most of those issues were also related to UI Automation.
例外情况似乎取决于是否启用了平板电脑输入服务。如果我不得不猜测,错误发生在UI自动化代码中,该代码只在基于笔的输入可用(可能还有基于触摸的输入)时运行。我以前见过服务在WPF应用程序中产生不良的副作用,其中大多数问题也与UI自动化有关。
Since this appears to be a "first chance" exception (it gets handled somewhere in the framework), the only people who should notice are developers who have their IDE configured to break on all exceptions (as opposed to only unhandled exceptions). If that is indeed the case, and if those developers are not actually using the pen or touch input capabilities, it might be easiest to just disable the Tablet PC Input Service and move on with your lives.
由于这似乎是一个“第一次机会”异常(它在框架中的某个地方被处理),惟一应该注意的是开发人员,他们的IDE被配置为对所有异常进行中断(而不是只处理未处理的异常)。如果确实如此,而且这些开发人员实际上没有使用笔或触控输入功能,那么可能最简单的方法就是禁用平板电脑输入服务,然后继续你的生活。
Alternatively, you could configure Visual Studio to not break on that particular exception type, which only pertains to UI Automation anyway.
或者,您可以配置Visual Studio,使其不会中断特定的异常类型,这只与UI自动化有关。
Since things are pretty slow at the office this week, I will spend some additional time looking into this. If I can find a code-based solution, I will update my answer here. But from the look of it, the UI is constructed almost entirely programmatically, so this probably isn't something you can fix with a simple custom template.
由于本周办公室的工作进展非常缓慢,我将花一些额外的时间来研究这个问题。如果我能找到基于代码的解决方案,我将在这里更新我的答案。但是从它的外观来看,UI几乎是完全以编程的方式构造的,所以这可能不是您可以通过一个简单的自定义模板来修复的东西。
#2
3
If you look on the microsoft documentation it says:
如果你看一下微软的文档它说:
This exception can be raised if the element was in a dialog box that was closed, or an application that was closed or terminated.
如果元素在已关闭的对话框中,或者应用程序已关闭或终止,则可以引发此异常。
Could it be possible that you're closing the window on a "change month" event?
你是否有可能关闭一个“改变月”事件的窗口?
#3
3
It is difficult to reproduce your issue. The next suggestions may help you:
很难再现你的问题。下面的建议可能对你有所帮助:
-
another process may affect to your program. Do you use utilities like
Snoop
orUISpy
?另一个过程可能会影响到您的程序。你使用像Snoop或UISpy这样的工具吗?
-
your problem may be related to low-performance hardware or vendor software bug. See here answer for resolving this issue
您的问题可能与性能低下的硬件或供应商的软件缺陷有关。请看这里解决这个问题的答案。
-
your problem may be related to rendering a copy of UI-control which doesn't exist for some reasons. See this discussion for more details
您的问题可能与呈现ui控件的副本有关,因为某些原因它不存在。有关更多细节,请参见本讨论
#4
2
(As I needed some diversion) I tried to do some research on your case and could reproduce the mentioned exception. Enabling .NET Framework source stepping and anything else I could find I was able to pinpoint the exception to the Invoke
method of the ElementUtil
class in the PresentationCore.dll
. The corresponding code of the method looks like this:
(因为我需要转移一下注意力)我试着对你的案例做一些研究,并且可以重现上面提到的例外。在PresentationCore.dll中,启用。net Framework源代码步进和其他任何我能找到的功能,我能够确定ElementUtil类的调用方法的异常。方法对应的代码如下:
internal static object Invoke(AutomationPeer peer, DispatcherOperationCallback work, object arg)
{
Dispatcher dispatcher = peer.Dispatcher;
// Null dispatcher likely means the visual is in bad shape!
if( dispatcher == null )
{
throw new ElementNotAvailableException();
}
Exception remoteException = null;
bool completed = false;
object retVal = dispatcher.Invoke(
DispatcherPriority.Send,
TimeSpan.FromMinutes(3),
(DispatcherOperationCallback) delegate(object unused)
{
try
{
return work(arg);
}
catch(Exception e)
{
remoteException = e;
return null;
}
catch //for non-CLS Compliant exceptions
{
remoteException = null;
return null;
}
finally
{
completed = true;
}
},
null);
if(completed)
{
if(remoteException != null)
{
throw remoteException;
}
}
else
{
bool dispatcherInShutdown = dispatcher.HasShutdownStarted;
if(dispatcherInShutdown)
{
throw new InvalidOperationException(SR.Get(SRID.AutomationDispatcherShutdown));
}
else
{
throw new TimeoutException(SR.Get(SRID.AutomationTimeout));
}
}
return retVal;
}
Taking this code into consideration the (in my opinion) only possible reason is, that the specified dispatcher is null
. Altough I find the comment
考虑到这段代码(在我看来),唯一可能的原因是,指定的分派器是空的。尽管我找到了评论
// Null dispatcher likely means the visual is in bad shape!
//空调度器可能意味着视觉效果不佳!
funny, I have actually no idea why this is the case. I tired to debugging that fact but was unable to get any meaningful information. Only following stacktrace (which opened my eyes again about what is going on if we "just click a button"):
有趣的是,我不知道为什么会这样。我厌倦了调试这个事实,但却无法得到任何有意义的信息。只有遵循stacktrace(它再次睁开我的眼睛,告诉我如果我们“点击一个按钮”会发生什么):
PresentationCore.dll!MS.Internal.Automation.ElementUtil.Invoke(System.Windows.Automation.Peers.AutomationPeer peer, System.Windows.Threading.DispatcherOperationCallback work, object arg)
PresentationCore.dll!MS.Internal.Automation.ElementProxy.GetPropertyValue(int property)
[Native to Managed Transition]
UIAutomationCore.dll!ProviderCallouts::RawGetPropertyValue(struct IRawElementProviderSimple *,int,struct tagVARIANT *)
UIAutomationCore.dll!ProviderCallouts::GetPropertyValue(struct IRawElementProviderSimple *,unsigned short,class ProviderEntryPoint *,int,struct tagVARIANT *)
UIAutomationCore.dll!InProcClientAPIStub::GetPropertyValue(char *)
UIAutomationCore.dll!InProcClientAPIStub::InvokeInProcAPI(struct ITargetContextInvoker *,enum Protocol_MethodId,...)
UIAutomationCore.dll!AccessibleProxy::IsControl(struct IRawElementProviderFragment *,struct ITargetContextInvoker *)
UIAutomationCore.dll!AccessibleProxy::NormalizeUpwards(struct IRawElementProviderFragment *,struct ITargetContextInvoker *,struct IRawElementProviderFragment * *)
UIAutomationCore.dll![thunk]:EditProxy::Release`adjustor{32}' (void)
UIAutomationCore.dll!_UiaReturnRawElementProvider@16()
[Managed to Native Transition]
UIAutomationProvider.dll!MS.Internal.Automation.UiaCoreProviderApi.UiaReturnRawElementProvider(System.IntPtr hwnd = 0x000406ce, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, System.Windows.Automation.Provider.IRawElementProviderSimple el = {MS.Internal.Automation.ElementProxy})
UIAutomationProvider.dll!System.Windows.Automation.Provider.AutomationInteropProvider.ReturnRawElementProvider(System.IntPtr hwnd = 0x000406ce, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, System.Windows.Automation.Provider.IRawElementProviderSimple el = {MS.Internal.Automation.ElementProxy})
PresentationCore.dll!System.Windows.Interop.HwndTarget.CriticalHandleWMGetobject(System.IntPtr wparam, System.IntPtr lparam, System.Windows.Media.Visual root, System.IntPtr handle)
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, System.IntPtr wparam, System.IntPtr lparam)
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x0000003d, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x0000003d, System.IntPtr wParam = 0xffffffff, System.IntPtr lParam = 0x00000149)
[Native to Managed Transition]
user32.dll!__InternalCallWinProc@20()
user32.dll!InternalCallWinProc()
user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,void *,struct HWND__ *,enum _WM_VALUE,unsigned int,long,void *,int)
user32.dll!_DispatchClientMessage@24()
user32.dll!___fnDWORD@4()
ntdll.dll!_KiUserCallbackDispatcher@12()
user32.dll!_SendMessageTimeoutW@28()
oleacc.dll!NativeIAccessibleFromWindow(unsigned long,unsigned long,struct HWND__ *,unsigned long,struct _GUID const &,void * *)
oleacc.dll!_ORIGINAL_AccessibleObjectFromWindow@24()
oleacc.dll!_AccessibleObjectFromWindow@16()
oleacc.dll!_AccessibleObjectFromEvent@20()
oleacc.dll!_EXTERNAL_AccessibleObjectFromEvent@20()
msctf.dll!_AccessibleObjectFromEvent@20()
msctf.dll!CThreadInputMgr::OnAccFocusEvent()
msctf.dll!WinEventProc()
user32.dll!___ClientCallWinEventProc@4()
ntdll.dll!_KiUserCallbackDispatcher@12()
[Managed to Native Transition]
UIAutomationProvider.dll!MS.Internal.Automation.UiaCoreProviderApi.UiaRaiseAutomationEvent(System.Windows.Automation.Provider.IRawElementProviderSimple provider = {MS.Internal.Automation.ElementProxy}, int eventId = 0x00004e25)
UIAutomationProvider.dll!System.Windows.Automation.Provider.AutomationInteropProvider.RaiseAutomationEvent(System.Windows.Automation.AutomationEvent eventId = {System.Windows.Automation.AutomationEvent}, System.Windows.Automation.Provider.IRawElementProviderSimple provider = {MS.Internal.Automation.ElementProxy}, System.Windows.Automation.AutomationEventArgs e = {System.Windows.Automation.AutomationEventArgs})
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.RaiseAutomationEvent(System.Windows.Automation.Peers.AutomationEvents eventId)
PresentationCore.dll!System.Windows.Automation.Peers.AutomationPeer.RaiseFocusChangedEventHelper(System.Windows.IInputElement newFocus)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject focus, int timestamp)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject newFocus, System.Windows.Input.IKeyboardInputProvider keyboardInputProvider, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject focus, bool askOld, bool askNew, bool forceToNullIfFailed)
PresentationCore.dll!System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement element)
PresentationCore.dll!System.Windows.UIElement.Focus()
PresentationFramework.dll!System.Windows.Input.KeyboardNavigation.Navigate(System.Windows.DependencyObject currentElement, System.Windows.Input.TraversalRequest request, System.Windows.Input.ModifierKeys modifierKeys, System.Windows.DependencyObject firstElement)
PresentationFramework.dll!System.Windows.FrameworkElement.MoveFocus(System.Windows.Input.TraversalRequest request)
PresentationFramework.dll!System.Windows.Controls.Primitives.CalendarItem.FocusDate(System.DateTime date)
PresentationFramework.dll!System.Windows.Controls.Calendar.OnCalendarButtonPressed(System.Windows.Controls.Primitives.CalendarButton b, bool switchDisplayMode)
PresentationFramework.dll!System.Windows.Controls.Primitives.CalendarItem.Month_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Primitives.CalendarButton}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = true)
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Primitives.CalendarButton}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent)
PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Shapes.Rectangle}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false)
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Shapes.Rectangle}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted)
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 0x000406ce, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONUP, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 0x000406ce, int msg = 0x00000202, System.IntPtr wParam = 0x00000000, System.IntPtr lParam = 0x005b0066)
[Native to Managed Transition]
user32.dll!__InternalCallWinProc@20()
user32.dll!InternalCallWinProc()
user32.dll!UserCallWinProcCheckWow(struct _ACTIVATION_CONTEXT *,void *,struct HWND__ *,enum _WM_VALUE,unsigned int,long,void *,int)
user32.dll!_DispatchMessageWorker@8()
user32.dll!_DispatchMessageW@4()
WindowsBase.ni.dll!69d4936c()
[Frames below may be incorrect and/or missing, native debugger attempting to walk managed call stack]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)
PresentationFramework.dll!System.Windows.Application.Run()
WpfApp1.exe!WpfApp1.App.Main()
[Native to Managed Transition]
mscoreei.dll!__CorExeMain@0()
mscoree.dll!_ShellShim__CorExeMain@0()
mscoree.dll!__CorExeMain_Exported@0()
ntdll.dll!__RtlUserThreadStart()
ntdll.dll!__RtlUserThreadStart@8()
Just for fun here ist the same stacktrace as above in graphical form:
有趣的是,这里使用的是和上面一样的图形形式:
So my conslusion is that...
我的意思是……
- ...Mike Strobel's answer is the closest I've seen
- …迈克·斯特洛贝尔的回答是我见过的最接近的
- ...as of now I am curious myself
- …现在我自己也很好奇
#5
0
A possible work around would be to Try, Catch, Finally the UIAnimation exception and not raise any events (message boxes, error logs) when it occurs. Just let the code continue on as if nothing happened.
一个可能的工作是尝试,捕捉,最后是UIAnimation异常,当它发生时,不引发任何事件(消息框,错误日志)。让代码继续运行,就像什么都没发生一样。