title: Does using pinvoke marks .NET as being unsafe?
body: <p>When using pointers in .NET with the <code>[unsafe]</code> attribute the code must be marked as unsafe using <code>/unsafe</code> option in <code>csc</code> for instance. </p>
  
  <p>But what happens when I use PInvoke, to me it all seems that compiled assembly will be considered as safe managed code while it may contain potential <em>security</em> issues, right ?</p>
  
  <p>NB: This is both bad and good, because it is a way to use fast pointer operations without having to mark the assembly as <code>/unsafe</code>.</p>
  
  <p>For instance</p>
  
  <pre><code>extern "C" __declspec(dllexport) void foo(double* samples)
  {
      *samples = 42.0;
  }
  </code></pre>
  
  <p>Called by:</p>
  
  <pre><code>[DllImport("native.dll")]
  static extern void foo(double[] samples);
  </code></pre>
  
  <p>Or more explicitly (which is the default marshaling):</p>
  
  <pre><code>[DllImport("native.dll")]
  static extern void foo([MarshalAs(UnmanagedType.LPArray)] double[] samples);
  </code></pre>