I'm facing issue with outofmemoryexception, with error message caught by App_DispatcherUnhandledException (1 of some error messages):
Message: Zgłoszono wyjątek typu 'System.OutOfMemoryException'. Source: PresentationFramework
StackTrace:
w System.Windows.TreeChangeInfo.CreateParentInheritableProperties(DependencyObject d, DependencyObject parent, Boolean isAddOperation)
w System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
w System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent)
w System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
w System.Windows.Media.Visual.AddVisualChild(Visual child)
w System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
w System.Windows.FrameworkTemplate.WireRootObjectToParent(Object createdObject, DependencyObject rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
w System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
w System.Windows.FrameworkTemplate.<>c__DisplayClass45_0.<LoadOptimizedTemplateContent>b__2(Object sender, XamlObjectEventArgs args)
w System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
w System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
w System.Xaml.XamlObjectWriter.WriteEndObject()
w System.Xaml.XamlWriter.WriteNode(XamlReader reader)
w System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
w System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
w System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
w System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
w System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
w System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
w System.Windows.FrameworkElement.ApplyTemplate()
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Control.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureCell(IColumnElement column, GridViewCellBase cell, Size size)
w Telerik.Windows.Controls.GridView.GridViewCellsPanel.RealizeAndMeasureCells(Int32 startIndex, Int32 predictedLastIndex, Func`2 calculateLastIndex)
w Telerik.Windows.Controls.GridView.GridViewCellsPanel.UpdateVirtualizedCells()
w Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureOverride(Size availableSize)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
w System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Control.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Border.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Control.MeasureOverride(Size constraint)
w Telerik.Windows.Controls.GridView.GridViewRowItem.MeasureOverride(Size availableSize)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RealizeRows(Int32 startIndex, Int32 endIndex, Double& verticalOffset, HashSet`1& realizedRows)
w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.MeasureOverride(Size availableSize)
w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
w System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
w Telerik.Windows.Controls.GridView.GridViewScrollViewer.MeasureOverride(Size availableSize)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Control.MeasureOverride(Size constraint)
w Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride(Size availableSize)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
w System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
w System.Windows.UIElement.Measure(Size availableSize)
w System.Windows.ContextLayoutManager.UpdateLayout()
w System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
w System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
w System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
w System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
w System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
HResult: -2147024882
Here are some informations:
Application runs on RDS, with 15-25 users using application
Available memory: 32 GB
Avg useed memory: 17 GB
There is never a situation, when used memory hits 30 GB (highest peak was around 23 GB)
CPU is fine, avg 40%, peaks to 60% used
RAM usage per app instance grows with usage to, around 1.5 GB per instance.
App was profiled multiple times, there are 0 memory leaks, according to VS Profiler, and other profilers (including JetBrains one)
App uses Telerik libraries
App uses Entity Framework
I'm stuck and have no idea where to look for potential issues. Optimization took me weeks and it went pretty well - I've managed to fix typical memory leaks and memory distribution issues, sometimes app needs to launch GC.Collect() manually, but it happens rarely. There is also no pattern, when OutOfMemoryException hits, leaving me with no clue, where to look for an issue.
Last thing, in my opinion the application is too big for WPF, due to classic WPF memory growth (app goes from 60K to 1.5k of ram usage in span of couple hours), but I have no choice other, than fixing this issue.
Edit
I'm not an admin on RDS environment, there is another engineer doing deployment and administration, maybe there is some kind of changes he possibly made, that started to cause this problem?
"There are 0 memory leaks" is a strong statement. Memory leaks typically reveal in very specific scenarios, so you should profile each possible workflow to state that - and this is impractical/impossible for larger apps. So the best thing you can do is probably to interview the users about their usage patterns and try to reproduce the leak locally with a profiler attached.
Also, investigating the call stack for the OutOfMemoryException is not always useful, as any allocation could cause it if there is not enough memory (so Telerik are maybe not to blame, though you can check their feedback portal for public issues mentioning memory or OutOfMemoryException.
Otherwise, as suggested in the comments, most of the good profilers detect common memory leaks, and even common WPF memory leaks, but, again, you have to run the app through the specific scenario (e.g. open and close a specific window), take the snapshots, and investigate the profiler suggestions.
Last, by default WPF app run as an x86 process, giving them practically maximum of ~2GB of memory. Of course, there are class of apps that just need more memory (e.g. working with huge text streams in memory), if this is your case, you can try switching the app to x64 process, which will allow much more (16TB? if I remember) memory. Just have in mind that this could increase your memory even more (as simple types now use twice more memory) and could potentially slow down your application. Running x64 apps with the debugger attached also have some caveats.
It will be hard to figure out the exact cause like this but I can suggest some troubleshooting mechanisms.
Your stack trace suggests you are using a Telerik gridview. Try commenting it out or replacing with a normal gridview and see if the exception still comes. That way at least you can be sure which element is the culprit. Once you confirm which element is causing the issue, try creating a custom control by inheriting from the same type. Then in all the methods add logs call the base method. This way you will not lose the functionality at the same time can confirm what's going wrong.
Check if your running into some kind of infinite loop. The call-stack suggests that when it is trying to render all your elements it is running out of memory. This can come if there is some kind of ItemSource involved which is way too huge or so cyclic dependent controls are used.
Related
I've no idea where is this coming from. Following is the complete stack trace in debug mode. How to find the root cause?
Following stack trace doesn't say much about the Source of the error, and inner exception is null sadly.
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.AddLogicalChild(Object child)
at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.PropertyChangedCallback.Invoke(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.CoerceValue(DependencyProperty dp)
at System.Windows.Controls.DataGridHelper.TransferProperty(DependencyObject d, DependencyProperty p)
at System.Windows.Controls.Primitives.DataGridColumnHeader.PrepareColumnHeader(Object item, DataGridColumn column)
at System.Windows.Controls.Primitives.DataGridColumnHeadersPresenter.PrepareContainerForItemOverride(DependencyObject element, Object item)
at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
at System.Windows.Controls.DataGridCellsPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
at System.Windows.Controls.DataGridCellsPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized)
at System.Windows.Controls.DataGridCellsPanel.GenerateChild(IItemContainerGenerator generator, Size constraint, DataGridColumn column, Int32& childIndex, Size& childSize)
at System.Windows.Controls.DataGridCellsPanel.DetermineRealizedColumnsBlockList(Size constraint)
at System.Windows.Controls.DataGridCellsPanel.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
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)
Update1: The issue was fixed by using
HeaderTeamplate = {StaticResource BALimitedHeaderTemplate}
Instead of
<DataGridTemplateColumn.Header>
<ContentPresenter ContentTemplate="{StaticResource BALimitedHeaderTemplate}" x:Name="_BAContentPresenter"/>
</DataGridTemplateColumn.Header>
Lines above with ContentPresenter are part of a user control that is added dynamically to a Parent window multiple times. I am still not sure, why adding the user control (seperate instances) to the window is causing the exception though - and more strangely only in .Net framework 4.0 but not in 4.5 and above.
Update 2: Apparently it's a bug in Framework V4.0, and usage seems pretty legitimate. This issue is fixed in Framework 4.5 and Above! We worked around this using HeaderTemplate. Someone else has tried to describe this problem in following link.
http://impulsecode.blogspot.sg/2012/01/in-wpf-getting-error-specified-element.html
I have a WPF application built on .NET 4.5. The latest version of the map control (version 1.0.1.0) is causing an issue if it is used within a datatemplate. This does not happen with the previous version I was using from NuGet (version 1.0.0.0). It is easy to reproduce the issue:
MainWindow.xaml:
<Window x:Class="MicrosoftMapError.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Content="{Binding ViewModel,
RelativeSource={RelativeSource Self}}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Views/MapView.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
</Window>
MainWindow.cs:
using MicrosoftMapError.ViewModels;
using System.Windows;
namespace MicrosoftMapError
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.ViewModel = new MapViewModel();
}
public object ViewModel
{
get { return (object)GetValue(ViewModelProperty); }
set { SetValue(ViewModelProperty, value); }
}
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(
"ViewModel",
typeof(object),
typeof(MainWindow));
}
}
MapView.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
xmlns:viewModels="clr-namespace:MicrosoftMapError.ViewModels">
<DataTemplate DataType="{x:Type viewModels:MapViewModel}">
<Grid>
<wpf:Map />
</Grid>
</DataTemplate>
</ResourceDictionary>
The MapViewModel class is just an empty class; there is nothing interesting to see there.
And this is the stack trace for the exceptions.
Outer exception:
XamlParseException - The invocation of the constructor on type 'Microsoft.Maps.MapControl.WPF.Map' that matches the specified binding constraints threw an exception.
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Window.MeasureOverrideHelper(Size constraint)
at System.Windows.Window.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Interop.HwndSource.SetLayoutSize()
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
at System.Windows.Window.SetRootVisual()
at System.Windows.Window.SetRootVisualAndUpdateSTC()
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
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)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
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)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at MicrosoftMapError.App.Main() in d:\SoftwareDevelopment\Working\MicrosoftMapError\MicrosoftMapError\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Inner exception:
InvalidOperationException - Cannot perform this operation while dispatcher processing is suspended.
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(Delegate method, Object[] args)
at Microsoft.Maps.MapControl.WPF.Core.MapConfigurationFromWeb.ConfigLoaded(String requestKey, Dictionary`2 sections)
at Microsoft.Maps.MapControl.WPF.Core.MapConfigurationFromWeb.GetConfigurationSection(String version, String sectionName, String culture, MapConfigurationCallback callback, Boolean reExecuteCallback, Object userState)
at Microsoft.Maps.MapControl.WPF.Core.MapConfiguration.GetSection(String version, String sectionName, String culture, String key, MapConfigurationCallback callback, Boolean reExecuteCallback, Object userState)
at Microsoft.Maps.MapControl.WPF.Core.MapConfiguration.GetSection(String version, String sectionName, String culture, String key, MapConfigurationCallback callback, Boolean reExecuteCallback)
at Microsoft.Maps.MapControl.WPF.Map..ctor()
Are dev team has looked into this and I believe they have found the issue. They are working on putting together a new release. Also, Microsoft never officially released a Nuget package, someone just took some old buggy libraries and posted them on Nuget without asking Microsoft. We are planning to make an official Nuget package.
Does anyone know how to solve a crash in WPF where the call stack is completely in windows code.
Following is the call stack...
6/26/2014 3:29:05 PM: [FATAL] System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first.
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.AddLogicalChild(Object child)
at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
at System.Windows.Controls.TabItem.OnContentChanged(Object oldContent, Object newContent)
at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo, DependencyProperty dp)
at System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject container, FrugalStructList1& exclusionContainerDependents, FrugalStructList1& oldContainerDependents, FrugalStructList`1& newContainerDependents)
at System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle)
at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.Controls.ItemsControl.ApplyItemContainerStyle(DependencyObject container, Object item)
at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
at System.Windows.Controls.Panel.GenerateChildren()
at System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView view)
at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)
at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
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)
You're getting this error because you are trying to set a control (Visual) as the child of another Visual without first removing it from the visual tree. A Visual can never be in the visual tree in two places.
The difficult part is going to be tracking down what Visual is being inserted into the tree twice. You're going to have a really hard time catching it in the debugger (think nearly impossible), so you'll have to try some more creative debugging methods. If you can reproduce the problem consistently, maybe try stripping Visuals out one at a time and see which Visual is causing the problem that way. If you have some custom controls that are working with some lower level visual tree functionality, these are going to be highly suspect. Take a look at them first.
I have just started using Catel for a WPF application and I am having a few problems.
1) When a button cannot execute I do not see the button grayed out as per the documentation.
2) Where do I put code to persist values to a database - in the ViewModel or Model. Is there an example anywhere?
3) Is there an example of using a menu in a main page and loading user controls on the click of menu items?
4) When I set the DeferValidationUntilFirstSaveCall = true in the constructor of my ViewModel I get an exception when the dialog window shows up. The exception is as follows
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Catel.MVVM
StackTrace:
at Catel.Windows.Data.Converters.GetFirstValidationErrorConverter.Convert(Object value, Type targetType, Object parameter)
at Catel.Windows.Data.Converters.ValueConverterBase.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetValueFromStyleOrTemplate(FrameworkObject fo, DependencyProperty dp, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo, DependencyProperty dp)
at System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject container, FrugalStructList`1& exclusionContainerDependents, FrugalStructList`1& oldContainerDependents, FrugalStructList`1& newContainerDependents)
at System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle)
at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.Controls.TextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.FrameworkElement.UpdateStyleProperty()
at System.Windows.FrameworkElement.OnInitialized(EventArgs e)
at System.Windows.FrameworkElement.TryFireInitialized()
at System.Windows.FrameworkElement.EndInit()
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
at System.Xaml.XamlObjectWriter.Logic_EndInit(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndObject()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at FNZCIressClient.Views.AccountMappingWindow.InitializeComponent() in h:\Documents\iress-utils\FNZCIressClient\FNZCIressClient\Views\AccountMappingWindow.xaml:line 1
at FNZCIressClient.Views.AccountMappingWindow..ctor(AccountMappingViewModel viewModel) in h:\Documents\iress-utils\FNZCIressClient\FNZCIressClient\Views\AccountMappingWindow.xaml.cs:line 28
InnerException:
If I remove the defervalidation line from the code, the pop-up works.
Any help and advice appreciated.
1) Take a look at the examples repository, it has a lot of examples.
2) Override the Save() method
3) Use the UIVisualizerService or Prism to dynamically load regions
4) I will look into this. Are you just using the DataWindow or a custom one?
When i try to use a themes file in specific window, i can't add button to interface. vs 2012 Designer fire exception. I think there is confusion between themes files. Because i use them in 2 places :
my window contains the following resources section :
Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="themes\ShinyDarkGreen.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
and my app.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source ="themes\BureauBlue.xaml"/>
<ResourceDictionary Source ="themes\ResourceDictionary.xaml"/>
<ResourceDictionary Source="themes\GlassButton.xaml"/>
<ResourceDictionary Source="themes\Mesthemes.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The "BureauBlue.xaml" i used it in main window and i want to use ShinyDarkGreen.xaml in another windows. is there any way to achieve this
My OS Setting are French :
Exception : InvalidCastException : Impossible d'effectuer un cast d'un objet de type 'System.Windows.Media.Color' en type 'System.Windows.Media.Brush'.
à MS.Internal.Text.TextProperties.InitCommon(DependencyObject target)
à MS.Internal.Text.TextProperties..ctor(FrameworkElement target, Boolean isTypographyDefaultValue)
à System.Windows.Controls.TextBlock.GetLineProperties()
à System.Windows.Controls.TextBlock.EnsureTextBlockCache()
à System.Windows.Controls.TextBlock.MeasureOverride(Size constraint)
à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
à System.Windows.UIElement.Measure(Size availableSize)
à MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
à System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
à System.Windows.FrameworkElement.MeasureCore(Size availableSize)
à System.Windows.UIElement.Measure(Size availableSize)
à System.Windows.ContextLayoutManager.UpdateLayout()
à System.Windows.UIElement.UpdateLayout()
InnerException : aucun