How do I load only a signed assembly into a new AppDomain?

I am making a system addin where the main application loads the Addin1.dll and Addin2.dll assemblies at runtime in a new AppDomain.

However, if the signature of Addin1.dll is signed (strong name) and my key and Addin2.dll are not, I want to be able to load only Addin1.dll and reject Addin2.dll.

I suspect it needs to be done by setting some parameters in the AppDomainSetup?

0


source to share


3 answers


Have a look at Assembly.Load , which takes an Evidence parameter. You can find an example of how to generate evidence from your public key here .



+2


source


You can implement DomainManager and base your load / block solution on whatever you like. I have answered a somewhat related question here.



0


source


You can use the Load AppDomain class method to load a new assembly into the Appdomain if the assembly publisher policy is satisfied by the client or end-user environment.

Also a strong named assembly follows all the rules set by the assembly publisher and the CLR. Thus, the user of the assembly must satisfy the security aspect of the assembly loaded into the appdomain.

The CLR loads the referenced global assembly from the GAC using strong name properties. If the referenced assembly is available in the GAC, the CLR will return it containing a subdirectory and the file containing the manifest will be loaded. Finding an assembly in this way ensures the subscriber that the assembly loaded at runtime comes from the same publisher that created the assembly with which the code was compiled. Now comparing the public key token in the assemblyRef table of the assembly and the public key table in the referenced assemblies AssemblyDef. If the referenced assembly is not in the GAC, the CLR looks at the base application directory and then the private paths specified in the application configuration file; if the application containing the assembly is installed using the MSI, the CLR calls the MSI to download the required assembly. If the assembly is not found in any of these locations,an exception is thrown and finally the assembly fails.

0


source







All Articles