Catel WPF Deferred Validation - wpf

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?

Related

Elusive WPF Exception related to ToolTip

I have deployed a version of my (rather complex and sizeable) WPF Application and a few users (not all of them) encounter the following Exception.
FEHLER: Bei dem angegebenen Element handelt es sich bereits um das logische untergeordnete Element eines anderen Elements. Führen Sie zuerst eine Trennung durch.
bei System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
bei MS.Internal.FrameworkObject.ChangeLogicalParent(DependencyObject newParent)
bei System.Windows.FrameworkElement.AddLogicalChild(Object child)
bei System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
bei System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
bei System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
bei System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
bei System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
bei System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent()
bei System.Windows.Controls.PopupControlService.OnRaiseToolTipOpeningEvent(Object sender, EventArgs e)
bei System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
The english version of the exception message is:
Specified element is already the logical child of another element. Disconnect it first.
My main Problem is,
a) that I am not able to reproduce this on my development machine.
Which does not mean it does not occur under the same circumstances, rather the users all say independently that the Exception occurs at no specific point in time, action or state of the software.
b) none of the above calls are actually referring to my own code.
So I guess it must be somewhere in the XAML
I am completely lost and in hope of some pointers in a rough direction where to look.
EDIT: I have now been able to reproduce and isolate the problem
Demo Application
The Demo Application reproduces an Exception that will occur when a complex ToolTip (anything but a String Object) is placed on an Element (Button) which is in turn placed on a Popup.
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<ToggleButton x:Name="_PopUpToggle" Content="Open Popup"/>
<Popup
IsOpen="{Binding ElementName=_PopUpToggle,Path=IsChecked}"
Placement="Bottom"
>
<Grid Background="Wheat">
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Button
Content="StackPanelToolTip"
Click="Button_Click">
<Button.ToolTip>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Not "/>
<TextBlock Text="Plain"/>
</StackPanel>
</Button.ToolTip>
</Button>
</StackPanel>
</Grid>
</Popup>
</Grid>
To reproduce start the application, open the Popup, mouseover the first button, wait until the ToolTip appears and click. Repeat. This produces the following Exception with the corresponding TraceStack:
Bei dem angegebenen Element handelt es sich bereits um das logische untergeordnete Element eines anderen Elements. Führen Sie zuerst eine Trennung durch.
bei System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
bei System.Windows.FrameworkElement.AddLogicalChild(Object child)
bei System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
bei System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
bei System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
bei System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
bei System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent()
bei System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
The english version of the exception message is:
Specified element is already the logical child of another element. Disconnect it first.
Binding the ToolTip to a plain String Object (try the second Button) does work without any issue. This is my current workaround.
As pointed out by Mathew, enclosing the Complex Content of the ToolTip-Property in <ToolTip></ToolTip> resolves the issue.

in my silverlight app i am finding this error .Error HRESULT E_FAIL has been returned from a call to a COM component

in my silverlight app i am finding this error when i am trying to assign itemssource to listbox .Error HRESULT E_FAIL has been returned from a call to a COM component
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, Boolean b)
at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b)
at System.Windows.Controls.ItemsControl.ClearContainers(Boolean bHostIsReplaced)
at System.Windows.Controls.ItemsControl.ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
at System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable value)
at HRPMS.MyDesk.ConferenceRoomBooking.AddSourceToListBox()
at HRPMS.MyDesk.ConferenceRoomBooking.chkbxCCConsultant_Unchecked(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ToggleButton.OnUnchecked(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ToggleButton.OnIsCheckedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
at System.Windows.PropertyPathListener.ReconnectPath()
at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.b__3()
I had this a dozen times, if I remember correctly it usually occurred when there is a problem in the xaml of a View or Template the very moment it is instantiated or switched to visible (or a VisualState change is triggered).
Good candidates are:
references to StaticResources that cannot be found
VisualState change and a Target cannot be found, or a StaticResource cannot be found, or the new Value for a DiscreteObjectKeyFrame cannot be translated to the target type
for the last point compare these two, had this quite often:
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="True"/>
versus
<DiscreteObjectKeyFrame KeyTime="0:0:0">
<DiscreteObjectKeyFrame.Value>
<System:Boolean>True</System:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>

WPF Crash not in our code

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.

Devexpress thememanager routed event already used when instantiating prism view

I am building a business app based on a tiny variation of the Prism framework (couple of changes in behaviour but nothing in areas that would affect my issue.
I built a shell application, with a shell window that was created using the devexpress dxwindow wizard in vs2010. I created a region inside a devexpress layout panel for my main content. I then created a view, which also uses devexpress controls, in a separate project, that is then targeted at that region.
When the app starts and the view is registered and therefore "injected" (in the logical sense, not the DI or other programming concepts sense) into the region, I get one massive error that appears to be related to devexpress theming, but to be blunt, I don't know what the hell it's going on about. I should point out my WPF knowledge is gaining fast but still reasonably low.
Here's the details...
System.Windows.Markup.XamlParseException occurred
Message='The invocation of the constructor on type 'DevExpress.Xpf.LayoutControl.LayoutControl' that matches the specified binding constraints threw an exception.' Line number '14' and line position '10'.
Source=PresentationFramework
LineNumber=14
LinePosition=10
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
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 MyProject.Wpf.Modules.Partner.PartnerView.InitializeComponent() in c:\Workspace\Projects\MyProject\trunk\src\Wpf\MyProject.Wpf.Modules.Partner\PartnerView.xaml:line 1
at MyProject.Wpf.Modules.Partner.PartnerView..ctor() in C:\Workspace\Projects\MyProject\trunk\src\Wpf\MyProject.Wpf.Modules.Partner\PartnerView.xaml.cs:line 24
InnerException: System.Xaml.XamlObjectWriterException
Message=Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
Source=System.Xaml
LineNumber=0
LinePosition=0
StackTrace:
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.SetValue(Object obj, XamlMember property, Object value)
at System.Xaml.XamlObjectWriter.SetValue(Object inst, XamlMember property, Object value)
at System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndMember()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter)
at System.Windows.SystemResources.ResourceDictionaries.LoadDictionary(Assembly assembly, String assemblyName, String resourceName, Boolean isTraceEnabled)
at System.Windows.SystemResources.ResourceDictionaries.LoadGenericDictionary(Boolean isTraceEnabled)
at System.Windows.SystemResources.FindDictionaryResource(Object key, Type typeKey, ResourceKey resourceKey, Boolean isTraceEnabled, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
at System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference)
at System.Windows.StyleHelper.GetThemeStyle(FrameworkElement fe, FrameworkContentElement fce)
at System.Windows.FrameworkElement.UpdateThemeStyleProperty()
at System.Windows.FrameworkElement.OnThemeStyleKeyChanged(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.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.FrameworkElement.set_DefaultStyleKey(Object value)
at DevExpress.Xpf.Core.CornerBox..ctor()
at DevExpress.Xpf.Core.PanelControllerBase.CreateScrollBars()
at DevExpress.Xpf.Core.PanelControllerBase.CheckScrollBars()
at DevExpress.Xpf.Core.Controller.set_ScrollBars(ScrollBars value)
at DevExpress.Xpf.Core.ScrollControlController..ctor(IScrollControl control)
at DevExpress.Xpf.LayoutControl.LayoutControllerBase..ctor(ILayoutControlBase control)
at DevExpress.Xpf.LayoutControl.LayoutGroupController..ctor(ILayoutGroup control)
at DevExpress.Xpf.LayoutControl.LayoutControlController..ctor(ILayoutControl control)
at DevExpress.Xpf.LayoutControl.LayoutControl.CreateController()
at DevExpress.Xpf.Core.PanelBase..ctor()
at DevExpress.Xpf.Core.ScrollControl..ctor()
at DevExpress.Xpf.LayoutControl.LayoutControlBase..ctor()
at DevExpress.Xpf.LayoutControl.LayoutGroup..ctor()
at DevExpress.Xpf.LayoutControl.LayoutControl..ctor()
at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.InvokeDelegate(Action`1 action, Object argument)
at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CallCtorDelegate(XamlTypeInvoker type)
at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CreateInstance(XamlTypeInvoker type)
at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
InnerException: System.Windows.Markup.XamlParseException
Message=Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.
Source=PresentationFramework
LineNumber=0
LinePosition=0
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
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.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
at System.Windows.ResourceDictionary.set_Source(Uri value)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<Create_BamlProperty_ResourceDictionary_Source>b__1c4(Object target, Object value)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
InnerException: System.TypeInitializationException
Message=The type initializer for 'DevExpress.Xpf.Core.ThemeManager' threw an exception.
Source=DevExpress.Xpf.Core.v10.2
TypeName=DevExpress.Xpf.Core.ThemeManager
StackTrace:
at DevExpress.Xpf.Core.ThemeManager.get_TraceSwitch()
at DevExpress.Xpf.Utils.Themes.DefaultStyleThemeKeyExtension.RegisterThemeType()
at DevExpress.Xpf.Utils.Themes.DefaultStyleThemeKeyExtension.ProvideValue(IServiceProvider serviceProvider)
at System.Windows.ResourceDictionary.EvaluateMarkupExtensionNodeList(XamlReader reader, IServiceProvider serviceProvider)
at System.Windows.ResourceDictionary.GetKeyValue(KeyRecord key, IServiceProvider serviceProvider)
at System.Windows.ResourceDictionary.SetKeys(IList`1 keyCollection, IServiceProvider serviceProvider)
at System.Windows.ResourceDictionary.SetDeferrableContent(DeferrableContent deferrableContent)
at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<Create_BamlProperty_ResourceDictionary_DeferrableContent>b__168(Object target, Object value)
at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
InnerException: System.ArgumentException
Message=RoutedEvent Name 'ThemeChanged' for OwnerType 'System.Windows.DependencyObject' already used.
Source=PresentationCore
StackTrace:
at System.Windows.EventManager.RegisterRoutedEvent(String name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType)
at DevExpress.Xpf.Core.ThemeManager..cctor()
InnerException:
The view does work in a static app, ie not using regions, and not using other devexpress controls outside the view.
Many thanks.
I had a the same error a while ago. What I found was that I had multiple versions of the controls on my PC and it was mixing versions of DevExpress controls (for me it was 11.1 and 11.2).
if you're using a DevExpress template it may be worth checking to see what version of the controls it's adding as references. if you're using a newer version of the controls then this could lead to a version mismatch.

Frustrating error in WPF (.NET 4.0) internals: Hashtable insert failed. Load factor too high

I have built custom Rules Engine, where each element of this engine is a descendant of DependencyObject class, so that it could be described in XAML including support for dependency properties, markup extensions, bindings, and so on.
The purpose of this Rules Engine is to process certain information which comes as an input and to return the output information back to the queue.
The entire tree of object is being instantiated once (from XAML) in a single thread and the series of Input objects are being processed from the Input queue.
All works fine until I increase the number of threads - sometimes (not always!) it throws the following exception:
System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at MS.Internal.Data.ValueChangedEventManager.PrivateAddListener(Object source, IWeakEventListener listener, PropertyDescriptor pd)
at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
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.DependencyObject.SetValue(DependencyProperty dp, Object value)
...
So I wonder, is this a bug in WPF internals or I have to take a closer look at my code? Has anyone experienced such problem before?
Since I don't use any global thread-unsafe objects that may interfere with each other, I expect DependencyObject to work correctly in multi-threaded environment, correct?
Try using a lock() statement around every write to make sure that your writes are not happening simultaneously.

Resources