Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 11, 2025

The plugin loader was only loading plugin assemblies directly using Assembly.LoadFrom(), which doesn't resolve plugin dependencies properly. This caused plugins with NuGet dependencies (like SkiaSharp, Lucene.NET, etc.) to fail at runtime with assembly loading errors.

Changes

Added PluginLoadContext.cs: A custom AssemblyLoadContext that uses AssemblyDependencyResolver to create isolated plugin loading contexts. Each plugin gets its own context that can resolve dependencies from the plugin's .deps.json file.

Modified LoadPluginDLLs method: Changed from using Assembly.LoadFrom() to creating a PluginLoadContext for each plugin and using LoadFromAssemblyName() for proper dependency resolution.

Technical Implementation

The solution follows Microsoft's recommended pattern for plugin loading with dependencies:

  1. Each plugin gets an isolated AssemblyLoadContext marked as collectible for proper cleanup
  2. AssemblyDependencyResolver resolves both managed and unmanaged dependencies based on the plugin's .deps.json file
  3. Fallback to default load context for shared dependencies (like framework assemblies)

Testing

Added comprehensive tests including:

  • New test plugin TestPluginWithDependencies that uses Newtonsoft.Json to verify dependency loading
  • Unit test PluginLoaderTests to verify the fix works correctly
  • Integration test in BlakePluginTests for end-to-end validation

Before/After

Before: Plugins with dependencies would fail at bake time:

Error loading plugin from plugin.dll: Could not load file or assembly 'Newtonsoft.Json'

After: Plugins can now include any NuGet dependencies and they will be properly resolved and loaded, enabling use cases like:

  • SkiaSharp for SVG rendering
  • Indexing libraries for full-text search
  • Any other NuGet packages needed for plugin functionality

Fixes #34.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@github-actions github-actions bot added preview Triggers a release of preview version of Nuget packages enhancement New feature or request Blake.CLI dependencies Blake.BuildTools Blake.MarkdownParser Blake.Types labels Aug 11, 2025
Copilot AI changed the title [WIP] 🐛 Plugins don't load dependencies 🐛 Fix plugin dependency loading using AssemblyLoadContext Aug 11, 2025
Copilot AI requested a review from matt-goldman August 11, 2025 22:31
@matt-goldman matt-goldman added bug Something isn't working release Triggers a release of a production version of Nuget packages and removed preview Triggers a release of preview version of Nuget packages Blake.MarkdownParser Blake.Types labels Aug 11, 2025
Copy link
Owner

@matt-goldman matt-goldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot great work, please review comments. One of them is a requested change, for the other comment please either remove the file or respond to the comment clarifying why it needs to be kept.

Copilot AI requested a review from matt-goldman August 11, 2025 22:39
@matt-goldman matt-goldman marked this pull request as ready for review August 11, 2025 22:45
Copilot AI review requested due to automatic review settings August 11, 2025 22:45
@github-actions github-actions bot added the preview Triggers a release of preview version of Nuget packages label Aug 11, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug in the Blake plugin loading system where plugins with NuGet dependencies would fail at runtime due to improper assembly loading. The fix implements a proper plugin loading mechanism using AssemblyLoadContext to create isolated loading contexts for each plugin.

Key Changes

  • Added isolated plugin loading: New PluginLoadContext class creates separate loading contexts for each plugin with proper dependency resolution
  • Enhanced plugin loader: Modified the plugin loading logic to use AssemblyLoadContext instead of direct Assembly.LoadFrom()
  • Comprehensive testing: Added test plugin with dependencies and corresponding unit/integration tests to validate the fix

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Blake.BuildTools/Utils/PluginLoadContext.cs New custom AssemblyLoadContext for isolated plugin loading with dependency resolution
src/Blake.BuildTools/Utils/PluginLoader.cs Updated to use PluginLoadContext instead of Assembly.LoadFrom()
src/Blake.BuildTools/Blake.BuildTools.csproj Added InternalsVisibleTo for test access
tests/Blake.IntegrationTests/TestPluginWithDependencies/ Test plugin project with Newtonsoft.Json dependency to validate fix
tests/Blake.BuildTools.Tests/Utils/PluginLoaderTests.cs Unit tests for plugin loading functionality
tests/Blake.IntegrationTests/Commands/BlakePluginTests.cs Integration test for end-to-end plugin dependency loading

Copy link
Owner

@matt-goldman matt-goldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

@matt-goldman matt-goldman merged commit b613aa1 into main Aug 11, 2025
1 check passed
@matt-goldman matt-goldman deleted the copilot/fix-34 branch August 18, 2025 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Blake.BuildTools Blake.CLI bug Something isn't working dependencies enhancement New feature or request preview Triggers a release of preview version of Nuget packages release Triggers a release of a production version of Nuget packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Plugins don't load dependencies

2 participants