Using the IL Linker
Note
This article is about the .NET IL Linker, you can also view information about XAML and Resources Trimming.
WebAssembly
The linker step (also known as tree shaking, or IL Trimming) is responsible for the detection and removal of code that may not be used at runtime. This step is particularly important when targeting WebAssembly or native code in general, to reduce significantly the final package size.
The linker is generally efficient at removing code but in some cases it may remove too much code, making some assemblies fail to work properly. In particular, assemblies or features that rely on reflection don't work by default with the linker enabled. JSON.NET is a good example of this, as it relies on reflection very heavily.
To handle cases where the default linker behavior removes too much code, the linker can be manually configured using the LinkerConfig.xml file in Uno projects.
When parts of an application fail to work, you can:
- Add full assembly names to the
LinkerConfig.xmlfile:
<assembly fullname="MyAssembly" />
- Add namespaces for the linker to ignore:
<assembly fullname="MyAssembly">
<!-- This is required by Json.NET and any expression.Compile caller -->
<type fullname="MyNamespace*" />
</assembly>
As a troubleshooting step to determine if the linker is causing your code to break, you can also disable the linker completely by adding the following to your csproj file:
<PropertyGroup>
<WasmShellILLinkerEnabled>false</WasmShellILLinkerEnabled>
</PropertyGroup>
Note that disabling the linker is not recommended as it can force the compiler to generate very large WebAssembly modules AOT process, and go over the browser's size limits.
You can find additional information about the linker step in Uno Platform in the Linker configuration documentation.