Export (0) Print
Expand All

Sharing a Library with Partially Trusted Code 

Several steps must be completed before shared libraries can be called by partially trusted code. For an overview of this issue, see Using Libraries from Partially Trusted Code. You can enable partially trusted access to your libraries by completing the three following tasks:

Strong Name the Assembly

Before your library can be shared through the global assembly cache or used as a downloaded component, you must create a strong name. Complete the following tasks described in Creating and Using Strong-Named Assemblies to strong name your library:

  1. Create a key pair.

  2. Use the Assembly Linker (Al.exe) or an assembly attribute to apply the key pair to your library.

Disable the LinkDemand

To disable the implicit LinkDemand that blocks partially trusted code from calling shared libraries, apply the AllowPartiallyTrustedCallersAttribute at the assembly level of your code.

The following code example demonstrates how to apply the AllowPartiallyTrustedCallersAttribute attribute to a shared library.

[Visual Basic}

<assembly:AllowPartiallyTrustedCallersAttribute()>

[assembly:AllowPartiallyTrustedCallersAttribute()] 

When this attribute is present, all other security checks in your code still work as before, including any class-level or method-level declarative security attributes that are present. This attribute blocks only the implicit LinkDemand enforcement.

Share the Library

After the previous tasks are completed, you can share the library by placing it in the global assembly cache. For more information, see Installing an Assembly into the Global Assembly Cache.

NoteNote

If you want partially trusted callers to be able to call select classes or members in your library, you can place demands on those classes or members. For more information, see Requiring Full Trust for Types Within an AllowPartiallyTrustedCallersAttribute Assembly.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft