On my WPF app (.net 4.0) on a device without physical mouse (only touchscreen) a user as selected a value in a Combobox. After 6 minutes of "inactivity" (no action from the user or in the soft) a exception has been raised:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Input.StylusDevice.GetMouseButtonState(MouseButton mouseButton, MouseDevice mouseDevice)
at System.Windows.Controls.ComboBox.OnAutoScrollTimeout(Object sender, EventArgs e)
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
It seems after user explanation to reproduce the bug this exception appeared when an usb keyboard had been connected to the device.
I'm unable to reproduce the bug. Search on google didn't give me any leads
I've seen on the decompiled 4.0 framework code (I do not find 4.0 downloadable sources) and source browser (framework 4.6) here some leads:
private void OnAutoScrollTimeout(object sender, EventArgs e)
{
if (Mouse.LeftButton != MouseButtonState.Pressed || !this.HasMouseEnteredItemsHost)
return;
this.DoAutoScroll(this.HighlightedInfo);
}
The issue seems to come from :
public MouseButtonState LeftButton
{
get
{
return GetButtonState(MouseButton.Left);
}
}
protected MouseButtonState GetButtonState(MouseButton mouseButton)
{
//
if ( _stylusDevice != null && _stylusDevice.IsValid)
return _stylusDevice.GetMouseButtonState(mouseButton, this);
else
return GetButtonStateFromSystem(mouseButton);
}
[SecurityCritical, SecurityTreatAsSafe]
internal MouseButtonState GetMouseButtonState(MouseButton mouseButton, MouseDevice mouseDevice)
{
if (mouseButton == MouseButton.Left)
{
return _stylusLogic.GetMouseLeftOrRightButtonState(true);
}
if (mouseButton == MouseButton.Right)
{
return _stylusLogic.GetMouseLeftOrRightButtonState(false);
}
// can defer back to the mouse device that called you and it will call Win32
return mouseDevice.GetButtonStateFromSystem(mouseButton);
}
It's clearly possible the code has changed between framework release but even if some changes could impact this code, I do not see where a null reference exception can occurs.
Can anybody help me ?
Thanks
UPDATE: After more investigation I've found a part of the answer. While connecting the keyboard on the USB, it impacts the touch screen which is on the same hardware Usb internal hub. It seems windows is lost at this moment and the management of the "mouse" is impacted...