title: marshal_as, strings and fields vs. properties
body: <h1>include &quot;stdafx.h&quot;</h1>
  <pre><code>#include &lt;string&gt;
  #include &lt;msclr/marshal_cppstd.h&gt;
  
  ref class Test {
      System::String^ text;
      void Method() {
          std::string f = msclr::interop::marshal_as&lt;std::string&gt;(text); // line 8
      }
  };
  </code></pre>
  <p>This code when compiled with VS2008 gives:</p>
  <pre><code>.\test.cpp(8) : error C2665: 'msclr::interop::marshal_as' : none of the 3 overloads could convert all the argument types
          f:\programy\vs9\vc\include\msclr\marshal.h(153): could be '_To_Type msclr::interop::marshal_as&lt;std::string&gt;(const char [])'
          with
          [
              _To_Type=std::string
          ]
          f:\programy\vs9\vc\include\msclr\marshal.h(160): or       '_To_Type msclr::interop::marshal_as&lt;std::string&gt;(const wchar_t [])'
          with
          [
              _To_Type=std::string
          ]
          f:\Programy\VS9\VC\include\msclr/marshal_cppstd.h(35): or       'std::string msclr::interop::marshal_as&lt;std::string,System::String^&gt;(System::String ^const &amp;)'
          while trying to match the argument list '(System::String ^)'
  </code></pre>
  <p>But when I change the field into property:</p>
  <pre><code>    property System::String^ text;
  </code></pre>
  <p>then this code compiles without errors. Why?</p>