Assembly resolver scanner

Current version: 9.0

Sitecore uses assembly resolvers to scan the assemblies for types at runtime. Type scanning large collections of assemblies can be a resource-intensive task. You can configure which assemblies to include and exclude from this scan. Excluding assemblies can decrease startup time.

You can use three different strategies scanning assemblies:

  • Blacklist – loads all libraries except the ones listed in the excludedAssemblies node. Namespace: Sitecore.Web.AssembliesScanner.ExcludedAssembliesConfiguration.

  • Whitelist – loads only the libraries listed in the includedAssemblies node. Namespace: Sitecore.Web.AssembliesScanner.IncludedAssembliesConfiguration.

  • Mixed strategy – loads any whitelisted assembly that you have not blacklisted. Namespace: Sitecore.Web.AssembliesScanner.MixedAssembliesConfiguration.

You can also create a custom strategy.

Configure the inclusion and exclusion of assemblies

All assembly configuration is under the configurationAssemblies node. You specify the strategy that Sitecore uses by setting the type of this node, for example: Sitecore.Web.AssembliesScanner.ExcludedAssembliesConfiguration, Sitecore.Web.

Exclude (blacklist) assemblies

Specify the assemblies in the configurationAssemblies/excludedAssemblies node that you want to exclude as a list of assembly names. Assembly names that start with a name contained in the excludedAssemblies list are not scanned.

You can add your solution assemblies to the list if you know they do not contain types that are scanned.

Example:

RequestResponse
<excludedAssemblies hint="list">
    <excludedAssembly id="Antlr3.Runtime">Antlr3.Runtime</excludedAssembly>
    <excludedAssembly id="ComponentArt">ComponentArt</excludedAssembly>
    <excludedAssembly id="CsQuery">CsQuery</excludedAssembly>
    <excludedAssembly id="CustomFields">CustomFields</excludedAssembly>
</excludedAssemblies>

Include (whitelist) assemblies

Specify the assemblies in the configurationAssemblies/includedAssemblies node that you want to include as a list of assembly names. Assembly names that start with a name in the includedAssemblies list are scanned.

Example:

RequestResponse
<includedAssemblies hint="list">    <includedAssembly id="Sitecore.Mvc">Sitecore.Mvc</includedAssembly>    <includedAssembly id="System.Web.Mvc">System.Web.Mvc</includedAssembly></includedAssemblies>

Mixed strategy

You can use the mixed strategy to list excludedAssemblies and includedAssemblies at the same time.

The following examples shows what happens when you use a mixed strategy.

Example 1:

RequestResponse
<excludedAssemblies hint="list">
    <excludedAssembly id="Sitecore.Mvc">Sitecore.Mvc</excludedAssembly>
</excludedAssemblies>
<includedAssemblies hint="list">
    <includedAssembly id="Sitecore.">Sitecore.</includedAssembly>
</includedAssemblies>

Result: Scans all of the *Sitecore*.* assemblies except Sitecore.Mvc.

Example 2:

RequestResponse
<excludedAssemblies hint="list">
    <excludedAssembly id="Sitecore.Mvc">Sitecore.Mvc</excludedAssembly>
</excludedAssemblies>
<includedAssemblies hint="list">
    <includedAssembly id="Sitecore.Mvc">Sitecore.Mvc</includedAssembly>
</includedAssemblies>

Result: Scans no assemblies.

Example 3:

RequestResponse
<excludedAssemblies hint="list">
    <excludedAssembly id="Sitecore.">Sitecore.</excludedAssembly>
</excludedAssemblies>
<includedAssemblies hint="list">
    <includedAssembly id="Sitecore.Mvc">Sitecore.Mvc</includedAssembly>
</includedAssemblies>

Result: Scans no assemblies.

Patch the configuration

If you add a configuration similar to this example in an include file, for example ExcludedAssembliesScanner.config, Sitecore patches the original file with what you specify:

RequestResponse
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <mvc>
            <configurationAssemblies type="Sitecore.Web.AssembliesScanner.ExcludedAssembliesConfiguration, Sitecore.Web">
                <excludedAssemblies hint="list">
                   <excludedAssembly id="MyTestWildCard1">MyTestWildCard1</excludedAssembly>
                   <excludedAssembly id="MyTestWildCard2">MyTestWildCard2</excludedAssembly>
                </excludedassemblies>
            </configurationAssemblies>
        </mvc>
    <sitecore>
</configuration>

All excludedAssembly nodes must have a unique ID.

Note

You can specify a server role for a node with a list of assemblies. If you do, Sitecore will only use the list for this server role. You specify the server role like this:

<excludedAssemblies hint="list" role:require="ContentDelivery">

Create a custom strategy

Follow these steps to create a custom strategy:

  1. Create a configuration class that inherits from the AssembliesConfiguration abstract class.

  2. Override the AssemblyFilter property in this class. The property must return an instance of the filter class.

  3. Create a filter class that implements IAssemblyFilter, and put all of the filter logic in the IsAllowed method.

Do you have some feedback for us?

If you have suggestions for improving this article,