Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF app crashes with KeyNotFoundException #2152

Open
DenSmoke opened this issue Nov 3, 2019 · 4 comments

Comments

@DenSmoke
Copy link

@DenSmoke DenSmoke commented Nov 3, 2019

  • .NET Core Version: 3.0.100
  • Windows version: Microsoft Windows 10.0.18362
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: not sure, but 4.7.2 had this bug also
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No

Problem description:
WPF App crashes sometimes randomly with KeyNotFoundException

Actual behavior:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at MS.Internal.WeakDictionary`2.get_Item(TKey key)
   at System.Windows.Automation.Peers.ItemPeersStorage`1.get_Item(Object item)
   at System.Windows.Automation.Peers.ItemsControlAutomationPeer.GetPeerFromWeakRefStorage(Object item)
   at System.Windows.Automation.Peers.ItemsControlAutomationPeer.AddProxyToWeakRefStorage(WeakReference wr, ItemAutomationPeer itemPeer)
   at System.Windows.Automation.Peers.ItemAutomationPeer.AddToParentProxyWeakRefCache()
   at MS.Internal.Automation.ElementProxy.StaticWrap(AutomationPeer peer, AutomationPeer referencePeer)
   at System.Windows.Automation.Peers.AutomationPeer.UpdateChildrenInternal(Int32 invalidateLimit)
   at System.Windows.Automation.Peers.AutomationPeer.UpdateChildren()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.ContextLayoutManager.fireAutomationEvents()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.UIElement.UpdateLayout()
   at System.Windows.Controls.VirtualizingStackPanel.<>c__DisplayClass94_0.<InitializeViewport>b__0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Expected behavior:
No error because this repo already has fix of .NET Framework 4.8:

if (_usesHashCode)
{
if (_hashtable == null || !_hashtable.ContainsKey(item))
return default(T);
return _hashtable[item] as T;
}

Minimal repro:
I can't even understand where and why this happens so don't know how it can be reproduced

@vatsan-madhavan

This comment has been minimized.

Copy link
Member

@vatsan-madhavan vatsan-madhavan commented Nov 4, 2019

@DenSmoke Do you have a crash-dump or a self-contained repro we can take a look at?

@DenSmoke

This comment has been minimized.

Copy link
Author

@DenSmoke DenSmoke commented Nov 4, 2019

@vatsan-madhavan Unfortunately I can't catch these crashes. I only get error reports from clients sometimes. I kept app running for 2 days with debugger but error didn't occur. I suspect app crashes with that exception on Windows 7 machines. I can't post code because of an NDA and can't create repro code because I don't know what causes it. But I can say that app uses no-codebehind design and almost every thing is written in XAML by a lot of Styles, DataTemplates, ControlTemplates.

If only I could get information what page or window gets this exception...

@mgnslndh

This comment has been minimized.

Copy link

@mgnslndh mgnslndh commented Nov 7, 2019

I've had this crash on my app as well. This was on .NET Framework 4.7.2. I also compared the source code of .NET 4.7.2 and 4.8 and found the Contains check in .NET 4.8. I've upgraded my app so it is no longer a problem.

As far as why the key was missing I do not know. The app i'm writing is using touch (and tabtip.exe) other than that no UI automation is used.

https://stackoverflow.com/questions/58656290/how-can-itempeersstorage-throw-exception-when-getting-value-from-weakdictionary

@DenSmoke

This comment has been minimized.

Copy link
Author

@DenSmoke DenSmoke commented Nov 7, 2019

@vatsan-madhavan I remembered that app uses Microsoft.Maps.MapControl.WPF package which uses .NET Framework 4.0. I suppose this package uses .NET Framework installed on client's PC. So that's why error is more distributed among Win7 users because they don't have .NET Framework 4.8 by default.
Is my assumption true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.