Skip to content
Open
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
23 changes: 20 additions & 3 deletions NanoXLSX.Core/Registry/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,26 @@ private static void LoadReferencedAssemblies()
.Select(a => a.Location);
HashSet<string> loadedPaths = new HashSet<string>(allLoadedPaths, StringComparer.InvariantCultureIgnoreCase);

List<string> referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
.Where(path => !loadedPaths.Contains(path))
.ToList();
// Guard the assembly-directory enumeration. Directory.GetFiles can throw (e.g. IOException
// "The parameter is incorrect" when BaseDirectory contains an entry the native enumerator
// cannot stat — observed when the host process's base directory is the Unity 6000.5.x editor
// install folder). Because this runs from WorkbookReader's static constructor, an unhandled
// throw here surfaces as a TypeInitializationException and permanently disables the reader
// for the whole AppDomain. Phase 1 above already registered plugins from loaded assemblies,
// so on enumeration failure we degrade to that result rather than crashing. This mirrors the
// per-path try/catch already used in the load loop below.
List<string> referencedPaths;
try
{
referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
.Where(path => !loadedPaths.Contains(path))
.ToList();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Failed to enumerate assemblies in {AppDomain.CurrentDomain.BaseDirectory}: {ex.Message}");
return;
}

foreach (string path in referencedPaths)
{
Expand Down