Unions of fixed size structures for use in safe context
<p>I'm working with packets that I can receive or send as a Byte array,
that has a fixed structure. So I'm trying to create an effective
union as follows:</p>

<pre><code>using System; // etc..

namespace WindowsApplication1
{
    public partial class Main : Form
    {
        public const int PktMaxSize = 124;
        // ...etc..
        // ...will use Pkt structure below...
    }

    [System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
    public struct Pkt
    {
        [System.Runtime.InteropServices.FieldOffset(0)]
        fixed Byte bytes[Main.PktMaxSize]; // complete byte pkt

        [System.Runtime.InteropServices.FieldOffset(0)]
        fixed Byte PktID[8];

        [System.Runtime.InteropServices.FieldOffset(8)]
        UInt16 Properties;

        // ...etc..
    }
}
</code></pre>

<p>I get a C# error</p>

<blockquote>
  <p>Pointers and size buffers may only be used in an unsafe context</p>
</blockquote>

<p>What do I need to do to be able to create and use "unsafe" structures in a safe env?</p>

<p>Thanks for your help - open to any suggestions as to how to handle packet structures that can easily be converted to and from a fixed byte stream being received by (or sent by) a C++ interop class.</p>
