Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Unity-MCP-Plugin/Assets/root/Runtime/UnityMcpPlugin.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using com.IvanMurzak.McpPlugin;
using com.IvanMurzak.ReflectorNet;
using com.IvanMurzak.Unity.MCP.Utils;
Expand Down Expand Up @@ -95,12 +97,39 @@ protected virtual McpPlugin.Common.Version BuildVersion()
return new UnityLoggerProvider();
}

/// <summary>
/// Filters assemblies to only include those that can successfully load their types.
/// This prevents ReflectionTypeLoadException from assemblies with missing dependencies.
/// </summary>
protected virtual IEnumerable<Assembly> GetSafeAssemblies()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.IsDynamic)
continue;

try
{
assembly.GetTypes();
yield return assembly;
}
catch (ReflectionTypeLoadException)
{
_logger.LogWarning("Skipping assembly with missing dependencies: {assembly}", assembly.GetName().Name);
}
catch (Exception ex)
{
_logger.LogWarning("Skipping assembly {assembly}: {error}", assembly.GetName().Name, ex.Message);
}
}
Comment thread
IvanMurzak marked this conversation as resolved.
}
Comment on lines +104 to +125
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The new GetSafeAssemblies() method lacks test coverage. Given that the repository has comprehensive test coverage (including tests for McpPlugin, ConnectionManager, and various tools), this new error handling logic should be tested. Consider adding a test that verifies assemblies with missing dependencies are properly skipped and logged, and that valid assemblies are correctly returned.

Copilot uses AI. Check for mistakes.

protected virtual IMcpPlugin BuildMcpPlugin(McpPlugin.Common.Version version, Reflector reflector, ILoggerProvider? loggerProvider = null)
{
_logger.LogTrace("{method} called.",
nameof(BuildMcpPlugin));

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = GetSafeAssemblies().ToArray();
var mcpPlugin = new McpPluginBuilder(version, loggerProvider)
.WithConfig(config =>
{
Expand Down