title: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect
body: <p>There are many questions regarding this error, but none seem related.</p>
  
  <p>The original exception we get</p>
  
  <blockquote>
    <blockquote>
      <p>Der eingehende Tabular Data Stream (TDS) für das RPC-Protokoll (Remote Procedure Call) ist nicht richtig. </p>
      
      <p>0-Tabellenwertparameter (""), Zeile 0, Spalte 0: Der 0xE7-Datentyp hat eine ungültige Daten- oder Metadatenlänge.</p>
    </blockquote>
  </blockquote>
  
  <p>My attempt at translating it</p>
  
  <blockquote>
    <blockquote>
      <p>The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect</p>
      
      <p>0-TableValuedParameter (""),Row 0, Column 0: The 0xE7-Datatype has an invalid Data- or Metadatalength.</p>
    </blockquote>
  </blockquote>
  
  <p>The Version of SqlServer</p>
  
  <blockquote>
    <blockquote>
      <p>Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) 
          Oct 28 2016 18:17:30 
          Copyright (c) Microsoft Corporation
          Standard Edition (64-bit) on Windows Server 2016 Standard 6.3  (Build 14393: ) (Hypervisor)</p>
    </blockquote>
  </blockquote>
  
  <p>What is causing this:</p>
  
  <p>We use user defined types to pass table valued parameters. The error is reproducable passing a DataTable with a single row and column containing a <code>String.Empty</code> as a prameter for a type like the following:</p>
  
  <pre><code>CREATE TYPE dbo.para_table_varchar AS TABLE (value nvarchar(10) COLLATE Latin1_General_ci_ai NOT NULL);
  </code></pre>
  
  <p>The C# Code (.net 4.6.1)</p>
  
  <pre><code>  DataTable table = new DataTable();
    DataColumn column = table.Columns.Add("value", typeof(string));
    column.MaxLength = 0;
    table.Rows.Add(string.Empty);
  
    SqlParameter para = _cmd.Parameters.Add("@ptable", SqlDbType.Structured, 0);
    para.Value = table;
    para.TypeName ="dbo.para_table_varchar";
  </code></pre>
  
  <p>The Command looks like this</p>
  
  <pre><code>SELECT * FROM someTable WHERE someColumn IN (SELECT value FROM @ptable)
  </code></pre>
  
  <p>This only happens on the mentioned SQLServer 2016. About 20 other clients do not have this issue. </p>
  
  <p>While Microsoft covers this issue <a href="https://support.microsoft.com/en-us/help/970519/you-receive-a-the-incoming-tabular-data-stream-tds-remote-procedure-ca" rel="nofollow noreferrer">here</a>, the suggested workarround (setting Size to -1) doesn't seem to work.</p>