Add shadow copy directory to ASP.NET AppDomain

I have already seen THIS and THIS question, but they are both several years old, and in my Maybe there is another solution:

I have an ASP.NET MVC 5 application with an IT based plugin system.
Thus, my ~/bin shadow copy using the framework, and my ~/Plugins folder uses a "manual shadow copy" on ~/Plugins/ShadowCopy in the pre-init application, as described in the link above.
So far, this has worked fine, as I now have the following case:

I am creating a separate limited AppDomain to execute some isolated code.
In order to be able to transfer objects with types defined in my assemblies to this domain, I install these ApplicationBase domains in the shadow copy directory of the main domain (if you do not load them there, you get a SerializationException when passing type / object to the second domain, because the assembly defining this type is loaded from different places).

Now I can transfer the types defined in my "base assemblies" to this second domain.
But as soon as I want to use the types defined in the plugin, this fails because the plugin assemblies are not in the default shadow copy directory, but in my "shadow copy help directory".
And since this directory is also in a completely different place, I cannot add it as PrivateBinPath , since they must be under the base path.

I am currently using the following workaround:

 #pragma warning disable 0618 AppDomain.CurrentDomain.SetShadowCopyPath(String.Join(";", HostingEnvironment.MapPath("~/bin"), HostingEnvironment.MapPath("~/Plugins/ShadowCopy"))); #pragma warning restore 0618 

in the pre-init method. This adds the “manual shadow dir copier” to the default, and my plugins are also shadow copies copied by the framework, and my second AppDomain is able to load them, and everything works more or less.

But since SetShadowCopyPath deprived of me, I now turn to my actual question:
I am looking for the best solution to avoid a deprived method.
I thought of the following solutions, but could not find out if / how this is possible:

  • Configure IIS to create an AppDomain using the AppDomainSetup.ShadowCopyDirectories property set to ~/bin and ~/Plugins/ShadowCopy via web.config
  • Move a copy of the shadow copy, for example. ~/bin/Plugins and tell IIS not to recycle the main AppDomain when changes are made to this folder (otherwise the application restarts with every request, since the pre-init method changes files every time)

Another idea would be to install a “manual shadow copier” in the directory under the default shadow copy, so instead of ~/Plugins/ShadowCopy something like C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\69da84c5\cd056104\Plugins , but is it wise to "interfere with frame folders"?

I am open to solving this problem, as well as a different approach to solving my underlying problem.

+6
source share

Source: https://habr.com/ru/post/973258/


All Articles