Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to mark a .net assembly as safe?
    primarykey
    data
    text
    <p>How do i mark as assembly as "safe"?</p> <p>Alternatively, how do i have Visual Studio tell me when something in my assembly is not "safe"?</p> <hr> <p>Sometimes you cannot use an assembly unless it is "safe" (e.g. <a href="https://stackoverflow.com/questions/1646980/why-wont-sql-server-register-my-assembly-as-safe">from SQL Server</a>).</p> <p>i would like my assembly to be marked as safe. If my assembly cannot be marked as safe because it's not safe, i'd like to know how i can know that my assembly is not safe.</p> <hr> <p>There are some concepts in Visual Studio that seem to relate to safe-ness, that may or may not have anything to do with an assembly being "safe": </p> <ol> <li><p><strong>Allow unsafe code</strong> assembly option:</p> <p><img src="https://i.stack.imgur.com/wUlxv.png" alt="enter image description here"></p> <ul> <li>What is allowed if i check the <em>allow unsafe code</em> option?</li> <li>What is not allowed if i uncheck the <em>allow unsafe code</em> option?</li> <li><p>What relation, if any, does "unsafe code" have to do with an assembly being "safe"?</p> <p>(i ask because my assembly doesn't "allow unsafe code", but allows P/Invoke calls - which i thought was the definition of "unsafe")</p></li> </ul></li> <li><p><strong><a href="http://msdn.microsoft.com/en-us/library/bhc3fa7f.aspx" rel="nofollow noreferrer">ClsCompliant</a></strong> assembly option:</p> <pre><code>[assembly: CLSCompliant(true)] namespace MyApplication </code></pre> <ul> <li>What is the relation, if any, does "cls compliant" code have to do with an assembly being "safe"?</li> </ul></li> <li><p><strong>unsafe</strong> code block:</p> <pre><code>int error; unsafe { error = 0x80004005; } </code></pre> <p>The code inside the <code>unsafe</code> block is "unsafe"</p></li> <li><p><a href="http://msdn.microsoft.com/en-us/library/ms182161.aspx" rel="nofollow noreferrer"><strong>UnsafeNativeMathods</strong></a></p> <p>Microsoft recommends creating a class called <code>UnsafeNativeMethods</code> that contain unsafe managed code:</p> <pre><code>[SuppressUnmanagedCodeSecurity] internal static class UnsafeNativeMethods { ... } </code></pre> <p>This contrasts with <code>SafeNativeMethods</code>:</p> <pre><code>[SuppressUnmanagedCodeSecurity] internal static class SafeNativeMethods { ... } </code></pre> <p>that contains safe native methods, and <code>NativeMethods</code>:</p> <pre><code>internal static class SafeNativeMethods { ... } </code></pre> <p>that contain native methods.</p></li> </ol> <p>How do i mark as assembly as "safe"?</p> <p>How does SQL know that as assembly is "not safe"?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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