Context

 
pelican140.png
Trying to run a piece of code in a sandbox, I encountered the “That assembly does not allow partially trusted callers.” exception when using cache.

Since I were unable to find any sample code which solves the issue, here's an application which shows in its revision 17587 the problem raised by the usage of cache in partial trust environments, and in its revision 17588, how this issue was solved.

You may also be interested by my related question on Stack Overflow.

Solution

The issue was solved by moving the calls to the cache object from partial trust, i.e. the plug-in, to the full trust, i.e. the caller. In practice, adapter pattern was used to pass the cache wrapper to the plug-in. The plug-in is unaware of the precise implementation of the cache, which makes it possible to use the cache without encountering the previously seen exception.

The same pattern can be used for other parts of the .NET Framework which aren't working in a partial trust context.

Misc

Microsoft StyleCop rules: followed.
Microsoft FxCop rules: not followed.
Accessibility: N/A.
Technical documentation provided: no.

Last edited Jun 25, 2012 at 3:35 PM by Arsene, version 2