Skip to content

System.Windows.Markup.XamlParseException in System.Runtime when published trimmed #4321

@Symbai

Description

@Symbai

Description

Publishing a WPF application using the trim unused assemblies option (VS -> Build dialog) throws a System.Windows.Markup.XamlParseException on start of the application. Publishing untrimmed works fine.

Configuration

image

Other information

 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295
System.Windows.Markup.XamlParseException: An exception was thrown by calling the constructor for type "Aaaa.MainWindow" that matches the specified binding restrictions.

 ---> System.TypeInitializationException: The type initializer for 'System.Windows.Window' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Windows.FrameworkElement' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Windows.Documents.TextElement' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Windows.Documents.Typography' threw an exception.
 ---> System.IO.FileNotFoundException:

File name: 'System.Runtime, Version = 5.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'
   at System.Windows.Media.TextFormatting.TextRunTypographyProperties.OnPropertiesChanged ()
   at MS.Internal.Text.TypographyProperties.ResetProperties ()
   at MS.Internal.Text.TypographyProperties..ctor ()
   at System.Windows.Documents.Typography..cctor ()
   --- End of inner exception stack trace ---
   at System.Windows.Documents.TextElement..cctor ()
   --- End of inner exception stack trace ---
   at System.Windows.FrameworkElement..cctor ()
   --- End of inner exception stack trace ---
   at System.Windows.Window..cctor ()
   --- End of inner exception stack trace ---
   at System.Windows.Window..ctor ()
   at Aaaa.MainWindow..ctor ()
   --- End of inner exception 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)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo (Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent (Uri resourceLocator, Boolean bSkipJournaledProperties)
   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)

The trim feature has removed the following files, several of them sounds pretty much mandatory for EVERY app to me and shouldn't be trimmed:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions