we have a defined a visual plugin in a .NET assembly. The host application is developed in Delphi.
This VisualPlugin loads and works just fine, For several years already
We recently added a new feature to our software. When this feature is activated, several instances of our delphi hydra host application are spawned simultaneously.
This is where we sporadically receive the following error (from unit uHYRes):
err_CannotInstantiateManagedPlugin = ‘Unable to instantiate managed plugin class “%s”. Most likely the type is not declared as “public”, type or assembly are marked as ComVisible(false), or missing/incorrect license file is detected.’;
The error is raised in the function uHYManagedSupport.CreateManagedPluginInstance.
The type is public and marked as ComVisible. Otherwise it would never work.
So the problem must be related with the license file.
The licence file is also obviously valid, otherwise trying to instantiate the visual plugin would always fail.
My guess is that the problem might be concurrent access to the license file. We have several delphi hosts trying to acess the license file at the ‘same’ time, so I guess that the file is locked while being read, which would then cause any other attempt to read the license file to fail, while still locked.
Can you please check your code to access the licencse file in regards to concurrency? If you are locking the file, can you please avoid doing so?
Any other suggestions/ideas that might help us overcome this problem?
Coul you try to update to the latest Beta to see if this behavior persist?
There is no such thing as license file. License checks are performed based on a precompiled license information bundled with the plugin assembly (this is how the .NET licensng system works).
Note that err_CannotInstantiateManagedPlugin doesn’t necessarily means that there was license error. This could be a different exceptin thrown in the constructor. Do you have any complex logic in the plugin constructor?
Just to clarify, we are not using multiple threads, but multiple independent processes (exe’s).
The problem seems to be these processes are all trying to access the same plugin assembly simultaneously.
The problem has never happened when only one process is involved, but only started to appear once multiple processes were involved.
My guess is that:
The plugin assembly is locked for a short period during startup. If another process then tries to access the assembly while locked, it fails and generates the err_CannotInstantiateManagedPlugin error.
I am guessing the assembly gets locked when Hydra is loading it/checking the license file. So maybe you could check to see if the assembly is locked during loading.
Unfortunately I have no clue as to when the lock starts/ends.
What I do know is that the lock must not last long, otherwise this problem would occur every time. The problem only happens sporadically.
Could you try to update to the latest Hydra beta? It will provide more exception info. Also coult you send to support@ your code (strip out the actual business logic, I only need to take a look at its constructor/initialization code and code-behind file)?