Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, I've managed to solve this. For people who need to know:</p> <ol> <li>Create an assembly with the Host API in it and allow the add-in to reference it.</li> <li>Ensure the assembly that contains the Host API has the [AllowPartiallyTrustedCallers] attribute on at the assembly level and strong name the assembly.</li> <li>Ensure the Host API assembly is registered with the AppDomain as a full trust assembly (see <a href="http://blogs.msdn.com/b/shawnfa/archive/2005/08/08/449050.aspx" rel="nofollow">http://blogs.msdn.com/b/shawnfa/archive/2005/08/08/449050.aspx</a> on how to do this).</li> <li>Ensure the methods on the Host API that require escalated permissions are decorated with the <strong>[SecuritySafeCritical]</strong> attribute (.NET 4).</li> <li><p>Demand full trust at the start of each method you need escalated permissions and then remove the demand straight after. The code below provides a method that takes a delegate which will be run in full trust.</p> <pre><code>/// &lt;summary&gt; /// Runs the supplied delegate using full trust /// &lt;/summary&gt; /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt; /// &lt;param name="func"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; private static T RunWithFullTrust&lt;T&gt;(Func&lt;T&gt; func) { //NOTE: This line grants the method full trust new PermissionSet(PermissionState.Unrestricted).Assert(); <pre><code>T result = func(); //Undo the grant for full-trust! CodeAccessPermission.RevertAssert(); return result; </code></pre> } </code></pre></li> </ol> <p>Also, prior to loading any add-ins ensure that the Host API is loaded into the restricted AppDomain. This'll avoid exceptions where the Host API assembly cannot be found.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload