XamlParseException only in some installations

Heiko 1,216 Reputation points
2021-09-25T12:43:17.797+00:00

I have a WPF Desktop Bridge app in the store. In the App Center I can see that some installations throw a XamlParseException in Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) during the call to MainWindow.InitializeComponent(). On my developer PC everything works fine. However, the Xaml designer underlines CommandBindings in the MainWindow.xaml file as warnings.

135197-commandbindings.png

namespace CompactStore  
{  
	public static partial class CustomCommands  
	{  
		public static RoutedCommand	NewFolder = new RoutedCommand();  
		public static RoutedCommand	Delete = new RoutedCommand();  
		public static RoutedCommand	NewCompactStore = new RoutedCommand();  
		public static RoutedCommand	OpenCompactStore = new RoutedCommand();  
		public static RoutedCommand	OpenHistorie = new RoutedCommand();  
		public static RoutedCommand	Extract = new RoutedCommand();  
		public static RoutedCommand	Insert = new RoutedCommand();  
		public static RoutedCommand	InsertFromClipboard = new RoutedCommand();  
		public static RoutedCommand	CopyToClipboard = new RoutedCommand();  
		public static RoutedCommand	Move = new RoutedCommand();  
		public static RoutedCommand	OpenSettings = new RoutedCommand();  
		public static RoutedCommand	Enter = new RoutedCommand();  
		public static RoutedCommand	OpenWith = new RoutedCommand();  
		public static RoutedCommand	GotoPrevious = new RoutedCommand();  
		public static RoutedCommand	GotoNext = new RoutedCommand();  
		public static RoutedCommand	GoUp = new RoutedCommand();  
		public static RoutedCommand	Find = new RoutedCommand();  
		public static RoutedCommand	Search = new RoutedCommand();  
		public static RoutedCommand	Rename = new RoutedCommand();  
		public static RoutedCommand	MoveDividerLeft = new RoutedCommand();  
		public static RoutedCommand	MoveDividerRight = new RoutedCommand();  
		public static RoutedCommand	ShowDoublets = new RoutedCommand();  
		public static RoutedCommand	DeepList = new RoutedCommand();  
		public static RoutedCommand	Help = new RoutedCommand();  
		public static RoutedCommand	ShowAppInfo = new RoutedCommand();  
		public static RoutedCommand	Play = new RoutedCommand();  
		public static RoutedCommand	Space = new RoutedCommand();  
		public static RoutedCommand	Mute = new RoutedCommand();  
	}  
}  

How can I determine what problem the installations have with the xaml file (line, offset)?

This is the first app where I use custom commands. Is there another way to implement custom commands, so that the xaml designer does not give warnings?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
790 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Heiko 1,216 Reputation points
    2021-09-27T10:41:14.227+00:00

    Hi HuiLiu,

    The warning I get from the Xaml designer, is visible in the screenshot above. Intellisense shows wrong errors (see image below). Whether the definition of the CommandBindings has anything to do with the XamlParseException is only a guess.

    135601-wrongintellisenseerrors.png

    The CommandBindings are defined in the namespace CompactStore (see image in my first post).

    In the app I catch an unhandled exception and send the stack trace along with some other information to the App Center. The original error message is in Polish, as the exception currently occurs in Polish installations. I'll show you the English translation. Here is the info I see in AppCenter:

    XamlParseException
    "Calling the constructor for the type "CompactStore.MainWindow" that conforms to the specified constraints of the binding caused 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.LoadBaml(XamlReaderxamlReader, 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 System.Windows.Application.DoStartup()
    at System.Windows.Application.<.ctor>b__1_0(Object unused)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    Exception.HResult: 0x80131501; X64, Windows.Desktop, WINDOWS 10.0.19042.1237

    The exception also occurs under WINDOWS 10.0.19043.1237.

    I use VS 2017 Community Edition.


  2. Heiko 1,216 Reputation points
    2021-10-13T17:55:53.68+00:00

    I created a test project. In it is the same xaml file that is in the real project and causes a XamlParseException in some installations. All handlers specified in the file have no function in the code-behind.

    Test project

    On some installations (different devices, different Windows 10 versions) I get the following message in the App Center:

    XamlParseException

    The invocation of the constructor on type 'CompactStore.MainWindow' that matches the specified binding constraints 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.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 System.Windows.Application.DoStartup()
    at System.Windows.Application.<.ctor>b__1_0(Object unused)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    0x80131501

    0 comments No comments

  3. Hemant Sahu 0 Reputation points
    2023-02-17T18:36:58.45+00:00

    After the patch update December 13, 2022-KB5021085 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows 10, version 1809 and Windows Server 2019 , while installation our window based application we are getting error.

    error

    An exception of type 'System.Windows.Markup.XamlParseException' occurred and was caught.
    ----------------------------------------------------------------------------------------
    12/27/2022 08:51:37
    Type : System.Windows.Markup.XamlParseException, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    Message : 'Initialization of 'Xceed.Wpf.Toolkit.Wizard' threw an exception.' Line number '617' and line position '19'.
    Source : PresentationFramework - AliOffice AssemblyVersion: 5.3.1.0
    Help link : 
    LineNumber : 617
    LinePosition : 19
    KeyContext : 
    UidContext : 
    NameContext : 
    BaseUri : pack://application:,,,/DAIOffice;component/deployment/ui/setup.xaml
    Data : System.Collections.ListDictionaryInternal
    TargetSite : Void RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
    HResult : -2146233087
    Stack Trace :    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)
    

    can same guide how to fix this issue


  4. Hemant Sahu 0 Reputation points
    2023-02-21T16:17:29.8833333+00:00
    0 comments No comments