Hello again, Jeremy.
Sorry for the late, I have been on vacation for the past two weeks. I have picked up this question again later this week.
What I have tried so far:
1. Create a bundle for the addin.
I have correctly put all my lib in the content folder and write the PackageContent.xml and the .addin file, but eventually, it failed to resolve the assembly.
2. Put the ".addin" file in "...Autodesk\Revit\Addins\2019\" folder.
And placed all dlls in that subdirectory, then make the addin file target the path of that subdirectory. It's failed too.
The interesting thing is that I run my command from the Addin Manager just one time, after that everything runs well magically!
With the tool "Process Monitor" that @awmcc90VZTT2 suggested, I found the Addin Manager loads all dlls relative whatever which command you have run the first time and all assembly resolves correctly.
Then, I came back to your solution of read the assembly file in a Stream and load from memory.
With lots of test, it works!
I create a class called ExternalAssemblyResolver. Here is my code.
internal class ExternalAssemblyResolver
{
public static void Register(string assemblyName)
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
var an = new AssemblyName(args.Name);
if (an.Name == assemblyName)
{
// Load external assembly path, remind put the 3rd party assembly in the same folder as your addin assembly.
string assemblyPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), assemblyName + ".dll");
using (Stream stream = new System.IO.MemoryStream())
{
if (File.Exists(assemblyPath))
{
byte[] data = File.ReadAllBytes(assemblyPath);
stream.Read(data, 0, data.Length);
return Assembly.Load(data);
}
}
}
return null;
};
}
}
Then, just add this line in the addin OnStartup function, it's done.
ExternalAssemblyResolver.Register("YourAssemblyNameWithoutExtension");
I think this will be the most easy way to load some external assembly for now.
Thanks a lot, and extremely grateful @awmcc90VZTT2 for all your suggestions .
Best regards,
Yousheng.