Page 1 of 1
Loading plugins in second instance of OD
Posted: Tue Jul 18, 2023 12:57 pm
by wjstarck
Is there a reason why plugins won't load when a second (or more) instance of Open Dental is launched?
This creates a lot of confusion for our customers. One scenario in particular is when person A is logged in to Windows and has OD running, and they switch users to person B without quitting their running instance of OD. When person B launches OD, the plugin doesn't load.
If they could be loaded, is this a feature request?
Re: Loading plugins in second instance of OD
Posted: Tue Jul 18, 2023 5:10 pm
by jsalmon
Not that I'm aware of. I just wrote a 'hello world' plug-in and it loaded up in both instances I just tested.
Code: Select all
using OpenDentBusiness;
using System.Windows.Forms;
namespace PluginHelloWorld {
public class Plugin : PluginBase {
public override bool HookAddCode(object sender,string hookName,params object[] parameters) {
switch(hookName) {
case "FormOpenDental.Load_end":
MessageBox.Show("Hello World!");
return true;
default:
return false;
}
}
}
}
Re: Loading plugins in second instance of OD
Posted: Tue Jul 18, 2023 8:31 pm
by wjstarck
Jason-
Thanks for that.
OK this is weird. Some time ago OD staff added myPlugin[VersionMajMin].dll to the Plug-in.dll field in the Program Link setup form so OD could select from a list of plugins and load the plugin that matched the running version of OD. So far so good.
So in my OD program directory there'll be a number of plugins
Anesthesia.dll
Anesthesia22.3.dll
Anesthesia22.4.dll
Anesthesia23.1.dll
OD will grab the matching plugin version, strip off the version number and rename it Anesthesia.dll and load it.
So, if I'm running, say, OD 23.1, I notice that if I remove Anesthesia23.1.dll from the OD program folder, the plugin will load in more than one instance of OD. If I put it back it will only run in the first instance.
Any idea why that would be the case?
Re: Loading plugins in second instance of OD
Posted: Wed Jul 19, 2023 8:45 am
by jsalmon
I have a theory based on the description from our website:
...For example, if using version 14.3.23, it would look for MyPlugin14.3.dll. If that file is found, it would replace MyPlugin.dll with the contents of MyPlugin14.3.dll, and then it would load MyPlugin.dll as normal. In a typical setting, this copy sequence gets triggered every time Open Dental starts up, ensuring a fresh copy of the dll. If Open Dental is on a newer version, and the dll is still on an older version with no matching [VersionMajMin], then Open Dental will attempt to load the old MyPlugin.dll.
https://www.opendental.com/manual/plugins.html
My theory is that the first instance of Open Dental has your plug-in dll tied up (it is using it) and the 'copy sequence' is failing. Therefore, the program ignores the failure and just launches Open Dental without the plug-in assembly loaded into memory. I'll create a ticket to have someone look into this. You could try moving all of the 'versioned' dlls out of the folder and see if you are then able to load your plug-in with multiple instances of Open Dental.
Re: Loading plugins in second instance of OD
Posted: Wed Jul 19, 2023 8:16 pm
by wjstarck
Jason-
I was able to modify the code in PluginLoader.LoadAllPlugins like so (<------ denotes modified code):
Code: Select all
string dllPathWithVersion = String.Empty; <----------------------------------------------
if (dllPath.Contains("[VersionMajMin]")) {
Version vers=Assembly.GetAssembly(typeof(Db)).GetName().Version;
dllPathWithVersion=dllPath.Replace("[VersionMajMin]",vers.Major.ToString()+"."+vers.Minor.ToString());
dllPath=dllPath.Replace("[VersionMajMin]","");//now stripped clean
if(File.Exists(dllPathWithVersion)) {
File.Copy(dllPathWithVersion,dllPath,true);
}
else{
//try the Plugins folder
if(PrefC.AtoZfolderUsed!=DataStorageType.InDatabase) {//must have an AtoZ folder to check
string dllPathVersionCentral=FileAtoZ.CombinePaths(ImageStore.GetPreferredAtoZpath(),"Plugins",
listPrograms[i].PluginDllName.Replace("[VersionMajMin]",vers.Major.ToString()+"."+vers.Minor.ToString()));
if(FileAtoZ.Exists(dllPathVersionCentral)) {
FileAtoZ.Copy(dllPathVersionCentral,dllPath,FileAtoZSourceDestination.AtoZToLocal,doOverwrite:true);
}
}
}
}
and a little lower:
Code: Select all
//The dll was found, try and load it in.
PluginBase plugin = null;
Assembly ass = null;
string assName = "";
try {
byte[] bytes = File.ReadAllBytes(dllPathWithVersion); <----------------------------------------
Assembly assembly = Assembly.Load(bytes); <----------------------------------------------
//ass =Assembly.LoadFile(dllPath); <-----------------------------------------------
assName = Path.GetFileNameWithoutExtension(dllPath);
string typeName = assName + ".Plugin";
Type type = assembly.GetType(typeName); <--------------------------------------
plugin = (PluginBase)Activator.CreateInstance(type);
This was modified from this little gem:
https://social.msdn.microsoft.com/Forum ... rplanguage
"Another option is to never load the actual assembly into the domain.
byte[] bytes = File.ReadAllBytes(@"C:\Users\billybob\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe");
Assembly assm = Assembly.Load(bytes);
This leaves the assembly on disk completely unrelated to the current application."
Re: Loading plugins in second instance of OD
Posted: Thu Jul 20, 2023 2:12 pm
by jsalmon
That is certainly an elaborate way to confirm my theory. Glad we were able to figure out the exact issue you were running into.
Re: Loading plugins in second instance of OD
Posted: Fri Aug 18, 2023 11:25 am
by jsalmon
Added the bug "Plug-ins are not loading in additional instances of Open Dental when using the update sequence" to our tracker and I'm training another engineer in the ways of plug-ins.
https://opendentalsoft.com:1943/ODBugTr ... sions.aspx
Re: Loading plugins in second instance of OD
Posted: Wed Aug 30, 2023 10:33 am
by jsalmon
The bug "Plug-ins were not loading in additional instances of Open Dental when using the update sequence" has been fixed and will be released with v23.1.45 and v23.2.15.
https://opendentalsoft.com:1943/ODBugTr ... sions.aspx
Re: Loading plugins in second instance of OD
Posted: Thu Sep 14, 2023 8:53 am
by wjstarck
Thanks for that Jason.
Definitely will cut down on the support calls
