# Trimming Problems

When protecting .NET projects with .NET Reactor, the injected protection algorithms may reference classes or members. If the project is deployed using the trimming option (e.g., for optimizing application size during publishing), these references might point to removed elements, leading to runtime errors or broken functionality.

# Solution

To ensure that the necessary classes and members are preserved during the trimming process, you can use the Eziriz.Reactor.TrimHelper NuGet package and provide additional configuration in your project.

# Steps to Resolve

  1. Install the NuGet Package

    Add the Eziriz.Reactor.TrimHelper NuGet package to your project. This package ensures the required classes and members used by the protection algorithms are not trimmed.

    dotnet add package Eziriz.Reactor.TrimHelper

    Alternatively, you can install it via the NuGet Package Manager in your IDE.

    NuGet Package Link: Eziriz.Reactor.TrimHelper

  2. Update the project file

    Add the following configuration to your project file (.csproj, .vbproj...) file to explicitly preserve all types and members within the TrimHelper assembly:

    <ItemGroup>
       <TrimmerRootAssembly Include="TrimHelper" />
    </ItemGroup>

    Read More: Root Assemblies

  3. Alternatively Update the Link XML File

    Add the following configuration to your link.xml file:

    <assembly fullname="TrimHelper">
      <type fullname="*" preserve="all"/>
    </assembly>

    Read More: Root Descriptors

    Below is an example link.xml file with the required entry for TrimHelper:

    <linker>
      <assembly fullname="TrimHelper">
        <type fullname="*" preserve="all"/>
      </assembly>
    </linker>



# Why This is Necessary

The trimming process removes unused code to reduce the application size. However, .NET Reactor's protection algorithms may rely on specific classes or members being available at runtime. Using the Eziriz.Reactor.TrimHelper package and updating project file (or link.xml) ensures these critical elements are preserved.

By following the steps above, you can safely use .NET Reactor with projects that utilize trimming without encountering runtime issues.