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.
SolutionThe 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.
MiscMicrosoft StyleCop rules: followed.
Microsoft FxCop rules: not followed.
Technical documentation provided: no.
Not affiliated with Microsoft and CodePlex
To remove your project or any question, please contact us: [email protected]