ConditionalAssemblyLoader 0.2.2-alpha

This is a prerelease version of ConditionalAssemblyLoader.
dotnet add package ConditionalAssemblyLoader --version 0.2.2-alpha
                    
NuGet\Install-Package ConditionalAssemblyLoader -Version 0.2.2-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConditionalAssemblyLoader" Version="0.2.2-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConditionalAssemblyLoader" Version="0.2.2-alpha" />
                    
Directory.Packages.props
<PackageReference Include="ConditionalAssemblyLoader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConditionalAssemblyLoader --version 0.2.2-alpha
                    
#r "nuget: ConditionalAssemblyLoader, 0.2.2-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConditionalAssemblyLoader@0.2.2-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConditionalAssemblyLoader&version=0.2.2-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=ConditionalAssemblyLoader&version=0.2.2-alpha&prerelease
                    
Install as a Cake Tool

ConditionalAssemblyLoader

ConditionalAssemblyLoader is a library for conditional loading of implementation assemblies for an interface assembly. The goal is to allow users to isolate code that would otherwise change from version to version and reference version-specific code via dependency injection.

Requirements

  • .NET Standard 2.0

Usage

Using ConditionalAssemblyLoader requires at least two projects:

  • The interface project, which provides the public API and is referenced by other projects. It produces the interface assembly.
  • The other projects are implementation projects, which reference the interface and provide the implementation to support the public API. They produce the implementation assemblies, one of which is loaded by ConditionalAssemblyLoader depending on the conditions at runtime.

First, reference ConditionalAssemblyLoader in the interface project.

  • Option 1: Directly reference ConditionalAssemblyLoader.dll.
  • Option 2: Install the ConditionalAssemblyLoader NuGet package.

In the interface project, create a type that derives from AssemblyLoader<T>. This will be used as the assembly loader.

  • AssemblyLoader<T> accepts a generic type parameter. The type represents the entry point into an implementation assembly and must be a class or interface.
  • Implement OnAssemblyLoaded() to perform any follow-up actions required to use the implementation assembly.
public sealed class MyAssemblyLoader : AssemblyLoader<MyEntryPoint>
{
    // ... other members
    
    public override void OnAssemblyLoaded(MyEntryPoint entryPoint)
    {
        // ... code here
    }
}

public abstract class MyEntryPoint
{
    // ... members go here
}

Next, reference the interface project in the implementation projects and create a type that derives from the entry point type.

public sealed class MyImplementationEntryPoint : MyEntryPoint
{
    // ... members + overrides go here
}

Back in the interface project, define a list of ConditionalAssemblyReferences for the assembly loader.

  • This can be done within the assembly loader type itself or externally by the user of the assembly loader.
  • A ConditionalAssemblyReference defines the conditions needed to use the referenced assembly it is associated with.
  • Each reference is evaluated in the order they are defined in References. Newer implementations should be listed ahead of older ones.
// in the assembly loader type
public sealed class MyAssemblyLoader : AssemblyLoader<MyEntryPoint>
{
    // ...
    
    public MyAssemblyLoader()
    {
        References.Add(new ConditionalAssemblyReference("MyImplementationAssembly", "Path/To/MyImplementationAssembly.dll"));
    }
}

// or externally
var loader = new MyAssemblyLoader();
loader.References.Add(new ConditionalAssemblyReference("MyImplementationAssembly", "Path/To/MyImplementationAssembly.dll"));

Finally, use the assembly loader, either within the interface project or in a different project that references the interface project.

var loader = new MyAssemblyLoader();
if (loader.TryLoad(out var loadedAssembly, out var error))
{
    var entryPoint = loadedAssembly.Instance;
    // ... other code
}
// ... other code

Mechanics

When the user attempts to load an implementation assembly through the created assembly loader (via AssemblyLoader.TryLoad()), it will iterate through the list of ConditionalAssemblyReferences and attempt to load the referenced assembly. During the process, it will attempt to resolve the name of the assembly, if supplied, by checking the directory where the loader's assembly is located. This is the default behavior of AssemblyLoader.ResolveAssemblyAtLoad(), which can be overridden by the user. If it cannot do so, it will attempt to load by using the supplied path.

Once an implementation assembly is successfully loaded, the loader will proceed with creating an instance of the entry point type. It will attempt to resolve assemblies by checking the currently loaded assemblies. This is the default behavior of AssemblyLoader.ResolveAssemblyAtEntryPoint(), which can also be overridden by the user. After the entry point is created, the loader will call AssemblyLoader.OnAssemblyLoaded() before returning both the loaded assembly and the entry point to the user.

License Info

This project is licensed under the Apache Public License 2.0.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2-alpha 150 12/26/2025
0.2.1-alpha 158 12/24/2025