Skip to content

Support for loading assemblies from Stream (for cloud storage scenarios) #304

@InCerryGit

Description

@InCerryGit

First of all, I would like to sincerely thank McMaster for providing such an excellent and user-friendly plugin library.

Is your feature request related to a problem? Please describe.

I'm trying to load plugin assemblies that are stored in AWS S3 object storage, but the current PluginLoader.CreateFromAssemblyFile() method only accepts file paths. This forces me to download the DLL from S3 to a temporary local file first, then load it from the file system. This approach introduces unnecessary I/O overhead, temporary file management complexity, and potential security concerns with storing sensitive DLLs on local disk.

Describe the solution you'd like

I would like PluginLoader to support loading assemblies directly from Stream objects. This would enable loading plugins from cloud storage services, compressed archives, or any other stream source without requiring intermediate file operations.

Proposed API:

// Basic stream loading
public static PluginLoader CreateFromStream(Stream assemblyStream, string assemblyName)

// With shared types
public static PluginLoader CreateFromStream(Stream assemblyStream, string assemblyName, Type[] sharedTypes)

// With configuration
public static PluginLoader CreateFromStream(Stream assemblyStream, string assemblyName, Action<PluginConfig> configure)

// With symbol stream support for debugging
public static PluginLoader CreateFromStream(Stream assemblyStream, Stream symbolStream, string assemblyName, Action<PluginConfig> configure)

Example usage:

// Download DLL from S3
using var s3Client = new AmazonS3Client();
var response = await s3Client.GetObjectAsync("my-plugins-bucket", "MyPlugin.dll");
using var assemblyStream = response.ResponseStream;

// Load plugin directly from stream
var loader = PluginLoader.CreateFromStream(assemblyStream, "MyPlugin");
var assembly = loader.LoadDefaultAssembly();

Describe alternatives you've considered

  1. Current workaround: Download S3 objects to temporary files, then use CreateFromAssemblyFile(). This works but adds complexity and performance overhead.

  2. Pre-loading to memory: Download all plugins to memory as byte arrays and use Assembly.Load(byte[]). However, this bypasses the plugin isolation and dependency resolution features that PluginLoader provides.

  3. Custom AssemblyLoadContext: Implement a custom AssemblyLoadContext that handles S3 loading. This would require duplicating much of the functionality already provided by this library.

Additional context

  • The underlying AssemblyLoadContext.LoadFromStream() method already supports stream-based loading, so this feature would primarily involve exposing this capability through the PluginLoader API
  • This feature would be valuable for cloud-native applications where plugin assemblies are stored in object storage (AWS S3, Azure Blob Storage, Google Cloud Storage, etc.)
  • Stream-based loading should automatically enable LoadInMemory mode for proper plugin isolation
  • This feature would complement existing file-based loading without introducing breaking changes
  • Many modern applications are moving towards cloud storage for better scalability, security, and cost efficiency

This feature request would make McMaster.NETCore.Plugins more suitable for cloud-native and distributed application architectures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions