question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trim in .net 6 breaks self contained single file publish mode

See original GitHub issue

Describe the bug References required for file dialogs will break. There’s an exception when trying to use them.

To Reproduce Steps to reproduce the behavior:

  1. Run an avalonia app with a folder dialog
  2. publish it with .net 6 with trim enabled
  3. see the exception

Desktop (please complete the following information):

  • OS: Windows
  • Version 0.10.8

Additional context Work around, add these settings into your project file

<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>

this will prevent the needed files from being trimmed, and prevent com from being disabled which is needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
maxkatz6commented, Oct 6, 2022

It was fixed in 11.0 preview.

2reactions
luthfiampascommented, Nov 9, 2021

I use the latest version (0.10.10). Actually, this problem occurs with OpenFileDialog as well. In Linux (Debian), IL trimming doesn’t break open folder/file dialog.

System.TypeLoadException
   at Avalonia.Win32.Interop.UnmanagedMethods.CoCreateInstance(Guid& clsid, IntPtr ignore1, Int32 ignore2, Guid& iid, Object& pUnkOuter)
   at Avalonia.Win32.SystemDialogImpl.<>c__DisplayClass1_0.<ShowFileDialogAsync>b__0() in /_/src/Windows/Avalonia.Win32/SystemDialogImpl.cs:line 26
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__271_0(Object )
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread )
--- End of stack trace from previous location ---
   at AvaloniaPlayground.Services.FileDialogService.OpenAsync() in /media/data/playground/AvaloniaPlayground/Services/FileDialogService.cs:line 19
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trim self-contained applications - .NET
Enable trimming · Add <PublishTrimmed>true</PublishTrimmed> to your project file. This property will produce a trimmed app on self-contained ...
Read more >
Trimming options - .NET
If you change the trim mode to partial , you can opt-in individual assemblies to trimming by using a <TrimmableAssembly> MSBuild item. XML...
Read more >
Shrinking a Self-Contained .NET 6 Wordle-Clone Executable
Shrinking a Self-Contained .NET 6 Wordle-Clone Executable. Shrinking the size of an executable in .NET can be more than just TrimMode.
Read more >
JsonConvert.DeserializeObjects does not work with trim ...
The method JsonConvert.DeserializeObjects works when "Trim unused code" publish setting is off. When I turn this setting on I get: Newtonsoft.
Read more >
Single File Apps In .NET 6 - NET Core Tutorials
NET 6 has the ability to trim unneeded dependencies from your application. By default, when you publish a self contained application you get ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found