title: Marshalling strings, C++ to C#: 'conversion is not supported by the library'
body: <p>Summary:</p>
  
  <p>When attempting to use marshalling to pass string data into a C++ DLL from C#, I'm getting </p>
  
  <blockquote>
    <p>'msclr::interop::error_reporting_helper&lt;_To_Type,_From_Type>::marshal_as':
    This conversion is not supported by
    the library or the header file needed
    for this conversion is not included. 
    Please refer to the documentation on
    'How to: Extend the Marshaling
    Library' for adding your own
    marshaling method.    c:\program
    files\microsoft visual studio
    9.0\vc\include\msclr\marshal.h    203</p>
  </blockquote>
  
  <p>I'm using Visual Studio 2008 Professional Edition; Visual C++ 2008; .Net 3.5.</p>
  
  <p>Detail:</p>
  
  <p>The method concerned (in its simplest form) is as follows:</p>
  
  <pre><code>LibDSSDLL::DssOutputSocketFacade::DssOutputSocketFacade(const System::String^ name)
  {
      marshal_context^ context = gcnew marshal_context();
      std::string n = context-&gt;marshal_as&lt;std::string&gt;(name);
  
      this-&gt;socket = new DssOutputSocket( n);
  }
  </code></pre>
  
  <p>The header includes in the order they are presented to the preprocessor are</p>
  
  <pre><code>#include "StdAfx.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;msclr\marshal_cppstd.h&gt;
  
  #using &lt;mscorlib.dll&gt;
  using namespace System;
  using namespace msclr::interop;
  </code></pre>
  
  <p>This looks to me as though it conforms to the example cited <a href="https://stackoverflow.com/questions/1300718/c-net-convert-systemstring-to-stdstring">here</a> and to the documentation at MSDN (Stack Overflow is refusing to let me cite a second URL); however clearly the C++ compiler is not finding the conversion it needs.</p>
  
  <p>What have I missed? I confess I'm not very expert with C++ or with Windows.</p>