This article is a mirror article of machine translation, please click here to jump to the original article.

View: 59779|Reply: 9

[Source] "Dynamic Replacement" for .NET Plugins

[Copy link]
Posted on 2021-8-15 21:55:14 | | |
Imagine a scenario where our service system provides a series of functional services, and more new functional services will be added in the future, and functional services may need to be changed or removed. A common basic requirement for such a service system is that the operation of the service system cannot be stopped when adding/removing/updating functional services. Normally, "hot-swapping plugins" can be implemented very easily by encapsulating each service into a plugin dll, but "hot replacement" ("dynamic replacement") of plugins becomes a problem. The reason is that when we uninstall a plugin Dll from the service system, the service system actually still holds the underlying reference to the dll, and if you try to delete or overwrite the dll, windows will give a message like "the dll is being used".

So how to solve this problem? I think there are at least two options:

(1) Use AppDomain. Loading plugins in a new AppDomain and then uninstalling the AppDomain cleanly unloads the plugin dlls from the service system. The downside of this approach is that you need to manage many AppDomains (because you have so many functional services), and communication across AppDomains is done in a remoting way, which introduces a lot of unnecessary headaches to our system. If you're interested, you can also try this option, and I prefer to use the second one.

(2) Copy the plugin Dll in memory, and then load the Dll in memory. In this way, the DLLs on the hard drive can be overwritten or deleted at will. Previously we loaded plugin Dll directly from the hard drive, like this:

Now, we need to turn a corner:


This solves the problem of "dynamic replacement" of plugins.





Previous:Spring Cloud records all request interface logs to MongoDB
Next:.NET/C# converts underscored field names to large hump forms
Posted on 2021-8-15 23:11:28 |
Such a big project, it's better to restart the server at night...
Posted on 2021-8-17 14:43:41 |
Thanks for sharing!~'
Posted on 2021-9-16 18:25:58 |
Test responses
Posted on 2021-9-17 21:39:18 |
Learn it
Posted on 2021-9-18 19:05:29 |
This post was last edited by fyxh66 on 2021-9-18 19:07

System.BadImageFormatException:“未能加载文件或程序集“12505088 bytes loaded from 3.3hook, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。试图加载格式不正确的程序。”IL 格式不正确。
  • var dll = Assembly.Load(addinStream);
86 also tried, no @小slag The boss has time to help take a look
 Landlord| Posted on 2021-9-18 22:08:32 |
fyxh66 posted on 2021-9-18 19:05
System.BadImageFormatException:“未能加载文件或程序集“12505088 bytes loaded from 3.3hook, Version=1 ...

Haven't encountered this problem.

There are two situations where the System.BadImageFormatException exception occurs: the target platform of the program is inconsistent > the system platform of the reference dll file is inconsistent.

Check: Are the .NET versions of the main program and plug-in dlls consistent, and the target platform consistent, or are the dlls not developed on .net?
Posted on 2021-9-19 16:17:56 |
Published on 2021-9-18 22:08
Haven't encountered this problem.

There are two situations when the System.BadImageFormatException exception occurs: the program target platform is inconsistent > the reference dll ...

Yes, the c++ dll...
 Landlord| Posted on 2021-9-19 17:01:33 |

That's definitely not good, the dynamic plugin here can only load .NET DLLs, and the DLLs calling C++ are not adjusted in this way
Posted on 2021-9-19 18:54:53 |
Xiaozha Posted on 2021-9-19 17:01
That's definitely not good, the dynamic plugin here can only load .net DLLs, and the DLLs calling C++ are not tuned like this...

Is there any way to call the dll in C++ by directly using the byte[] byteset of the dll to call the methods inside?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com