问题
My application creates multiple AppDomains and I manually configure the binding redirects via the SetConfigurationBytes method. I grab the config file, check for all assemblies installed on the private folder and then set the assemblyRedirect as on the example below. This is to ensure that I'll always use the shipped version of a given assembly:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.2.18.0" />
</dependentAssembly>
However, when an assembly being loaded in a different AppDomain depends upon the System.Net.Http assembly, I get the following error: System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances.
There's two possible ways I've saw to solving this: either by removing the <dependentAssembly>
element on the config for this DLL, or to add this assembly on the GAC.
I didn't like any of this because the first may cause problems with other assemblies and the second relies on the GAC, which some of my clients don't like.
Anyone have a different idea on how to solve this?
Thanks in advance.
来源:https://stackoverflow.com/questions/33892955/error-while-loading-assembly-on-separated-appdomain