Skip to content

Commit a06bbdc

Browse files
committed
fix plugin loading, if call executable from another folder
1 parent 4374f52 commit a06bbdc

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

MainWindow.xaml.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace PointCloudConverter
3030
{
3131
public partial class MainWindow : Window
3232
{
33-
static readonly string version = "04.04.2025";
33+
static readonly string version = "05.04.2025";
3434
static readonly string appname = "PointCloud Converter - " + version;
3535
static readonly string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
3636

@@ -104,7 +104,11 @@ private async void Main()
104104
////testwriter.Close();
105105
//externalWriters = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes()).Where(type => typeof(IWriter).IsAssignableFrom(type) && !type.IsInterface);
106106

107-
var pluginsDirectory = "plugins";
107+
// Get the directory of the running executable
108+
var exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
109+
110+
// Build absolute path to plugins folder
111+
var pluginsDirectory = Path.Combine(exeDir, "plugins");
108112

109113
if (Directory.Exists(pluginsDirectory))
110114
{

Tools/PluginLoader.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,31 @@ namespace PointCloudConverter.Plugins
1313
{
1414
public static class PluginLoader
1515
{
16-
static readonly string pluginDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Plugins");
16+
// Resolve plugin folder relative to the .exe location instead of current working directory
17+
static readonly string pluginDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins");
1718

1819
// TODO add logger, if needed
19-
//static ILogger Log;
20+
// static ILogger Log;
2021

2122
public static IWriter LoadWriter(string pluginName)
2223
{
23-
//Log = logger;
24+
// Log = logger;
2425

26+
// Build the full path to the plugin DLL
2527
string pluginPath = Path.Combine(pluginDirectory, pluginName + ".dll");
26-
//Log.Write($"Loading plugin at {pluginPath}");
27-
if (File.Exists(pluginPath) == false) throw new FileNotFoundException($"The plugin at {pluginPath} could not be found.");
2828

29-
// Load the plugin assembly
29+
// Log.Write($"Loading plugin at {pluginPath}");
30+
31+
// Check if the plugin DLL exists
32+
if (File.Exists(pluginPath) == false)
33+
throw new FileNotFoundException($"The plugin at {pluginPath} could not be found.");
34+
35+
// Load the plugin assembly from the DLL
3036
var pluginAssembly = Assembly.LoadFrom(pluginPath);
3137

32-
// Find the specific type 'PointCloudConverter.Writers.GLTF'
33-
var writerType = pluginAssembly.GetType("PointCloudConverter.Writers.GLB");
38+
// Find the specific type 'PointCloudConverter.Writers.<PluginName>'
39+
// This assumes the type name inside the DLL matches the filename
40+
var writerType = pluginAssembly.GetType("PointCloudConverter.Writers." + pluginName);
3441

3542
if (writerType == null)
3643
throw new InvalidOperationException($"No valid implementation of IWriter found in {pluginPath}");

0 commit comments

Comments
 (0)