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
the problem raised by the usage of cache in partial trust environments, and in its revision
, how this issue was solved.
You may also be interested by my
related question on Stack Overflow
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,
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.
Microsoft StyleCop rules: followed
Microsoft FxCop rules: not followed
Technical documentation provided: no