title: C# Garbage data in string from unmanaged Method
body: <p>I have a wrapper around an unmanaged Method:</p>
  
  <pre><code>[DllImport(DLL_LOCATION, CharSet = CharSet.Auto)]
  [return: MarshalAs(UnmanagedType.Bool)]
  private static extern Boolean voGetFirmwareVersion(StringBuilder s, ref uint d);
  </code></pre>
  
  <p>This is working fine, the StringBuilder is being filled with Chinese characters. Fortuantely I know what the text should read: </p>
  
  <p>"Camera 0057; FPGA 0009"</p>
  
  <p>What I am getting is:</p>
  
  <p>慃敭慲〠㔰㬷䘠䝐⁁〰㤰猀״״譗珉譞珉쬂☐״״造琞\u085cʩ״</p>
  
  <p>I have tried changing the CharSet to all combinations in my DLLImport flag and tried changing the returned strings encoding to no avail. Help me internet land!</p>
  
  <p>EDIT: The dll I am calling belongs to a Device I am currently programming. All the other functions are working but the one mentioned above will only give me Chinese characters.</p>
  
  <p>EDIT AGAIN: Below is the code I am using to call the method signature above:</p>
  
  <pre><code>private string getFirmware()
      {            
          uint r = 31;
          StringBuilder sb = new StringBuilder(31);
          bool result = voGetFirmwareVersion(sb,  ref r);
  
          if(!result)
          {
              MessageBox.Show("Error Getting Firmware");
          }     
  
          return sb.ToString();          
      }
  </code></pre>