-->

RibbonControlsLibrary XamlParseException issue VS

2019-05-27 02:23发布

问题:

I have an issue with RibbonControlsLibrary, from the beginning I'm not able to use those controls in my C# apps. The problem appears randomly, mostly after reboot. Sometimes reboot helps and it starts to run properly (without any code changes!). I tested some possibilities and the RibbonWindow control works until I put "Ribbon" control into code! Error is pointed on this control too. Strangest is that issue appears when I'm creating new WPF Ribbon Application! In fact code is as simplest as it can be, but still... Anyone had this problem? I tried to google it, but couldn't find anything about this.

I have XP so problem with OS blocking file does not count.

XAML:

<r:RibbonWindow x:Class="BioSYSTEM.MainWindow"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
 Title="Window1" Height="300" Width="300">
<DockPanel>
<r:Ribbon DockPanel.Dock="Top" Title="title">
</r:Ribbon>
</DockPanel>

</r:RibbonWindow>

vS gives me this:

System.Windows.Markup.XamlParseException
Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.
   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.LoadDeferredContent(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings parentSettings, Uri baseUri)
   at System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
   at System.Windows.ResourceDictionary.RealizeDeferContent(Object key, Object& value, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
   at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
   at System.Windows.ResourceDictionary.FetchResource(Object resourceKey, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
   at System.Windows.SystemResources.LookupResourceInDictionary(ResourceDictionary dictionary, Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
   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.OnInitialized(EventArgs e)
   at System.Windows.Controls.Menu.OnInitialized(EventArgs e)
   at System.Windows.FrameworkElement.TryFireInitialized()
   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at Microsoft.Windows.Controls.Ribbon.Ribbon.OnApplicationMenuChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) in e:\dd\WPFOOB\src\wpfoob\Ribbon\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\Ribbon.cs:line 1356
   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 Microsoft.Windows.Controls.Ribbon.Ribbon.OnLoaded(Object sender, RoutedEventArgs e) in e:\dd\WPFOOB\src\wpfoob\Ribbon\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\Ribbon.cs:line 1501
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   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)


System.Reflection.TargetInvocationException
Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at System.Windows.Markup.StaticExtension.GetFieldOrPropertyValue(Type type, String name, Object& value)
   at System.Windows.Markup.StaticExtension.ProvideValue(IServiceProvider serviceProvider)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)


System.ComponentModel.Win32Exception
HRESULT_FROM_WIN32(ERROR_NOT_FOUND)
   at Standard.HRESULT.ThrowIfFailed(String message) in e:\dd\WPFOOB\src\wpfoob\WindowChrome\Microsoft.Windows.Shell\Standard\ErrorCodes.cs:line 494
   at Standard.NativeMethods.GetCurrentThemeName(String& themeFileName, String& color, String& size) in e:\dd\WPFOOB\src\wpfoob\WindowChrome\Microsoft.Windows.Shell\Standard\NativeMethods.cs:line 2795
   at Microsoft.Windows.Shell.SystemParameters2._InitializeThemeInfo() in e:\dd\WPFOOB\src\wpfoob\WindowChrome\Microsoft.Windows.Shell\SystemParameters2.cs:line 227
   at Microsoft.Windows.Shell.SystemParameters2..ctor() in e:\dd\WPFOOB\src\wpfoob\WindowChrome\Microsoft.Windows.Shell\SystemParameters2.cs:line 313
   at Microsoft.Windows.Shell.SystemParameters2.get_Current() in e:\dd\WPFOOB\src\wpfoob\WindowChrome\Microsoft.Windows.Shell\SystemParameters2.cs:line 347 

回答1:

I had a client with the same exception thrown on startup.

It turned out that if the simplest ribbon application is launched with the compatibility option "Disable visual themes" then the application will gracefully crash.

In our case, the ribbon application is launched through another app. On our client machine, the last was having the compatibility option activated.



回答2:

If you look at the very last exception reported in your stack trace, it looks like it might be a problem with getting the name of the Windows XP Theme. Try changing your theme, and see if that helps.