title: System.TypeLoadException: Access is denied when using MessagePack
body: <p>I'm trying to use MessagePack to serialize my objects, but whenever I try to run the serialization I'm getting an Unhandled Exception error.</p>
  
  <p>Here's my code:</p>
  
  <p>CSCDP_TCPClient.cs</p>
  
  <pre><code>using System.Text;
  using System.Threading.Tasks;
  using System.Net.Sockets;
  using System.Diagnostics;
  using System.IO;
  using MsgPack;
  using MsgPack.Serialization;
  
  namespace CSCDPApp
  {
      class CSCDP_TCPClient
      {
          public void Connect(string server, int portno, Script Script)  
          {
  
              var serializer = MessagePackSerializer.Get&lt;Script&gt;();
              var tempstream = new MemoryStream();
              serializer.Pack(tempstream, script);
  
              tempstream.Position = 0;
  
              var deserializedObject = serializer.Unpack(tempstream);
              Debug.WriteLine("Same object? {0}", Object.ReferenceEquals(script, deserializedObject));
          }
      }
  }
  </code></pre>
  
  <p>Script.cs:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace CSCDPApp
  {
      class Script
      {
          public string cardID;
          public string time;
          public string device;
          public string command;
  
          public Script()
          {
              //Parameterless Constructor for serialization
          }
  
          public Script(string cardID, string time, string device, string command)
          {
              this.cardID = cardID;
              this.time = time;
              this.device = device;
              this.command = command;
          } 
      }
  }
  </code></pre>
  
  <p>And I'm just calling it in main with:</p>
  
  <pre><code>        CSCDP_TCPClient tcpclient = new CSCDP_TCPClient();
          Script tempscript = new Script("test1","test2","test3","test4");
          tcpclient.Connect("0.0.0.0",1,tempscript);
  </code></pre>
  
  <p>And here's the error I'm getting:</p>
  
  <pre><code>Unhandled Exception: System.TypeLoadException: Access is denied: 'MsgPack.Serial
  ization.MessagePackSerializer`1[CSCDPApp.Script]'.
     at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, I
  nt32 tk, ObjectHandleOnStack type)
     at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
     at System.Reflection.Emit.TypeBuilder.CreateType()
     at MsgPack.Serialization.EmittingSerializers.FieldBasedSerializerEmitter.Crea
  teConstructor[T]()
     at MsgPack.Serialization.EmittingSerializers.SerializerEmitter.CreateInstance
  [T](SerializationContext context)
     at MsgPack.Serialization.EmittingSerializers.ILEmittingSerializerBuilder`2.&lt;&gt;
  c__DisplayClass5a.&lt;CreateSerializerConstructor&gt;b__59(SerializationContext contex
  t)
     at MsgPack.Serialization.AbstractSerializers.SerializerBuilder`3.BuildSeriali
  zerInstance(SerializationContext context)
     at MsgPack.Serialization.AutoMessagePackSerializer`1..ctor(SerializationConte
  xt context, ISerializerBuilder`1 builder)
     at MsgPack.Serialization.MessagePackSerializer.CreateInternal[T](Serializatio
  nContext context)
     at MsgPack.Serialization.SerializationContext.GetSerializer[T](Object provide
  rParameter)
     at MsgPack.Serialization.MessagePackSerializer.Get[T](SerializationContext co
  ntext, Object providerParameter)
     at CSCDPApp.CSCDP_TCPClient.Connect(String server, Int32 portno, Script scrip
  t) in d:\TFS\MSVC 2013_CTSDev1\CommonComponents\sdnet\tools\CSCDPService\CSCDPAp
  p\CSCDP_TCPClient.cs:line 21
     at CSCDPApp.Program.Main(String[] args) in d:\TFS\MSVC 2013_CTSDev1\CommonCom
  ponents\sdnet\tools\CSCDPService\CSCDPApp\Program.cs:line 64
  </code></pre>
  
  <p>I have my visual studio project in my D: drive, and I've checked that permissions are correct. I have the MessagePack.dll in the same directory as all my compiled executeables and have the reference linked. Is there anything I might possibly be missing?</p>