Hello,
I'm developing a custom PDM task and encountering an assembly binding issue. When I register my DLL, the Solidworks PDM Task Executor looks for a version of System.Numerics.Vectors that isn't referenced in my project. My dependencies require different versions of this library, so I use a .config file with binding redirects to resolve version conflicts during development.
For further context, I also have added a method to my Addin, along with a static constructor registering this resolver to this: AppDomain.CurrentDomain.AssemblyResolve event handler.
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
string assemblyName = new AssemblyName(args.Name).Name;
// Get the directory where this add-in is located
string addinDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyPath = Path.Combine(addinDirectory, assemblyName + ".dll");
if (File.Exists(assemblyPath))
{
return Assembly.LoadFrom(assemblyPath);
}
// Try alternative paths for dependencies
string[] possiblePaths = new string[]
{
Path.Combine(addinDirectory, "Dependencies", assemblyName + ".dll"),
Path.Combine(addinDirectory, "lib", assemblyName + ".dll"),
Path.Combine(addinDirectory, "bin", assemblyName + ".dll")
};
foreach (string path in possiblePaths)
{
if (File.Exists(path))
{
return Assembly.LoadFrom(path);
}
}
// For System.* assemblies, try to load from GAC or .NET framework
if (assemblyName.StartsWith("System.") || assemblyName.StartsWith("Microsoft."))
{
try
{
return Assembly.Load(args.Name);
}
catch
{
// Try loading just the simple name
try
{
return Assembly.Load(assemblyName);
}
catch
{
// Last resort for framework assemblies
string frameworkPath = Path.Combine(
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows),
"Microsoft.NET", "Framework64", "v4.0.30319", assemblyName + ".dll");
if (File.Exists(frameworkPath))
{
return Assembly.LoadFrom(frameworkPath);
}
}
}
}
return null;
}
catch (Exception ex)
{
// Log to PDM debug output or file
System.Diagnostics.Debug.WriteLine(\\\$"Assembly resolve failed for {args.Name}: {ex.Message}");
return null;
}
} //resolver for an assembly
My questions:
• Is there a way to provide Solidworks PDM with a configuration file (such as an app.config or TaskHost.exe.config) so it recognizes these binding redirects when loading my add-in?
• If not, what is the recommended approach for handling dependency version conflicts in PDM task add-ins?
Any guidance or best practices would be greatly appreciated and Apologies if this is not a good question for this forum.
Thank you.
