Theme Manager bug

Docking/MDI for WPF Forum

Posted 1 month ago by Mihai Cuziac
Version: 20.1.0
Platform: .NET 4.0
Environment: Windows 10 (64-bit)
Avatar

Hi, 

We have a problem with an Excel VSTO addin that uses the WPF Syntax Editor. The same code was working fine in previous version and I've checked that we are calling the constructor from the ui thread (dispatcher.invoke).When we try to instantiate the syntax editor we get the following error:

System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'ActiproSoftware.Windows.Controls.SyntaxEditor.SyntaxEditor' that matches the specified binding constraints threw an exception.' Line number '64' and line position '14'. ---> System.Xaml.XamlObjectWriterException: The invocation of the constructor on type 'ActiproSoftware.Windows.Themes.SystemThemeCatalogRegistrar' that matches the specified binding constraints threw an exception. ---> System.TypeInitializationException: The type initializer for 'ActiproSoftware.Windows.Themes.ThemeManager' threw an exception. ---> System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at ActiproSoftware.Windows.Themes.ThemeManager.CuG()
at ActiproSoftware.Windows.Themes.ThemeManager..cctor()
--- End of inner exception stack trace ---
at ActiproSoftware.Windows.Themes.ThemeManager.RegisterThemeCatalog(ThemeCatalogBase catalog)
at ActiproSoftware.Windows.Themes.ThemeCatalogRegistrarBase`1.Register()
at ActiproSoftware.Windows.Themes.ThemeCatalogRegistrarBase`1..ctor()
at ActiproSoftware.Windows.Themes.SystemThemeCatalogRegistrar..ctor()
--- End of inner exception stack trace ---
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.CreateInstance(XamlType xamlType, Object[] args)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteEndObject()
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, Uri& dictionarySourceUri)
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 ActiproSoftware.Windows.Controls.SyntaxEditor.SyntaxEditor.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 ActiproSoftware.Windows.Controls.SyntaxEditor.SyntaxEditor..ctor()
--- End of inner exception stack trace ---
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 Fluence.Excel.AddinVSTO.WPF.VM.FormXmlEditor.InitializeComponent() in Z:\TFS\FluenceTech\Fluence\Fluence\Fluence.Excel.AddinVSTO.WPF\FormBuilder\FormXmlEditor.xaml:line 1

Thank you,

Mihai,

[Modified 1 month ago]

Comments (2)

Answer - Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mihai,

Can you put together a new simple sample project that shows this happening and send it to our support address so that we can work with that and see what change triggered this problem?  Please reference this thread in your e-mail and exclude the bin/obj folders from the ZIP you send so it doesn't get spam blocked.  Thanks!

On a side note, what happens if you call something like this on the main UI thread prior to SyntaxEditor ever loading?  The idea here being to force type intialization of ThemeManager prior to the exception scenario happening.

ThemeManager.CurrentTheme = ThemeNames.OfficeColorfulGreen;


Actipro Software Support

Answer - Posted 26 days ago by Mihai Cuziac
Avatar

Hello,

Problem has been fixed. the issue was that there was some code running before excel showed any ui, that was creating another Application so basically there were 2 Dispatchers running all along. Running the sugested code (ThemeManager.CurrentTheme = ThemeNames.OfficeColorfulGreen;) on the main Dispatcher threw the same error, but running it on the other one did work and from that moment Actipro controls could be instantiated on either one.

Mihai,

The latest build of this product (v2020.1.1) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.