I already saw THIS and THIS question, but they are both a few years old and in my case there is maybe another solution at all:
I have an ASP.NET MVC 5 application with a plugin system based on THIS.
So my ~/bin
folder is shadow copied by the framework and my ~/Plugins
folder is using the "manual shadow copy" to ~/Plugins/ShadowCopy
on application pre-init as describen in the link above.
This worked fine so far until now, as I have the following case now:
I create a separate restricted AppDomain
to execute some sandboxed code.
To be able to pass objects with types defined in my assemblies to this domain I set this domains ApplicationBase
to the shadow-copy directory of the main domain (if you do not load them from there you get a SerializationException
when passing the type/object to the second domain, because the assembly defining this type is loaded from different locations).
Now I can pass types defined in my "base assemblies" to this second domain.
But as soon as I want to use types defined in a plugin this fails, because the plugin assemblies are not in the default shadow copy dir, but in my "manual shadow copy directory".
And as this directory is also in a completely different location I can't add it as a PrivateBinPath
as they are required to be underneath the base path.
At the moment I use 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 copy dir" to the default shadow copy dirs and my plugins are also shadow copied by the framework and my second AppDomain
is able to load them and everything is working more or less.
But as SetShadowCopyPath
is depricated I am now getting to my actual question:
I am searching for a better solution to avoid the depricated method.
I thought of the following solutions, but was not able to find out if/how that would be possible:
- Configure IIS to create an
AppDomain
with theAppDomainSetup.ShadowCopyDirectories
property set to~/bin
and~/Plugins/ShadowCopy
viaweb.config
- Move the shadow copy dir to e.g.
~/bin/Plugins
and tell IIS to NOT recycle the mainAppDomain
on changes in this folder (otherwise the app restarts on every request as the pre-init method changes the files in there every time)
Another idea would be to set the "manual shadow copy dir" to be underneath the default shadow copy directory, 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 framework folders"?
I am open to a solution to this problem as well as a different approach to solve my base problem.