Programmatically Restrict Code Permissions

Problem

You want to dynamically load an assembly using reflection but prevent it from having the same permissions as your application.

Solution

Create a custom piece of evidence, and attach it to the dynamically loaded assembly. Give assemblies with this evidence lowered permissions.

Discussion

The .NET Framework uses code access security to give assemblies different permissions, depending on several factors. In some cases, you might want to lower these permissions for certain assemblies. For example, you might create an extensible application with a plug-in framework that allows extra functionality to be added by supplying a new assembly. Your code can instantiate the classes in this assembly through .NET ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.