System.Windows.Markup.XamlParseException in System.Runtime when published trimmed
See original GitHub issueDescription
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
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:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top Results From Across the Web
c# - Published WPF application exception
The only useful error info I see is System.Windows.Markup.XamlParseException . I've included all the necessary assembly used in the project, ...
Read more >Known trimming incompatibilities - .NET
Trimming relies on seeing all assemblies at build time, so it knows which code is used and cannot be trimmed away. Most plugin...
Read more >System.Windows.Markup Namespace
Indicates to XAML processors that the whitespace surrounding elements of the type in markup should be trimmed when serializing. Implements a markup extension ......
Read more >XamlParseException Class (System.Windows.Markup)
Represents the exception class for parser-specific exceptions from a WPF XAML parser. This exception is used in XAML API or WPF XAML parser...
Read more >Trim self-contained applications - .NET
Learn how to trim self-contained apps to reduce their size. .NET Core bundles the runtime with an app that is published self-contained and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is the target I use to configure trimming in my WPF application:
You can copy/paste it in your main csproj and if you still have an exception, you can add the trimmed assembly in the condition using
Or '%(Filename)' == 'NAME_OF_YOUR_ASSEMBLY'
.My assumption was that this was due to WPF assemblies not supporting trimming because they have not been annotated ie they have linker warnings.
@eerhardt thoughts?