title: Calling C++ dll from C#. "Cannot marshal 'return value': Invalid managed/unmanaged type combination."
body: <p>My Header file.</p>
  
  <pre><code>extern "C"  class MyFuncs
  {
   public:
      __declspec(dllexport) unsigned char PassImage(unsigned char buffer, int size);
  };
  </code></pre>
  
  <p>CPP file.</p>
  
  <pre><code>unsigned char MyFuncs::PassImage(unsigned char buffer, int size)
  {
      return buffer;
  }
  </code></pre>
  
  <p>All works well except when i am returning buffer back to my main application.</p>
  
  <pre><code>    [DllImport("ExampleDLL.dll", EntryPoint = "?PassImage@MyFuncs@Funcs@@QAEXEH@Z")]
      public static extern byte[] PassImage(byte[] a, int count);
  </code></pre>
  
  <p>The error occurs when i am return unsigned char to byte[].</p>
  
  <p>If i change byte[] to byte i get a value back an no error.</p>
  
  <p>This is the exact error:</p>
  
  <blockquote>
    <p>Cannot marshal 'return value': Invalid managed/unmanaged type
    combination.</p>
  </blockquote>
  
  <p>How can I accept back unsigned char to byte[]?</p>