title: D3D11 Create Shader: Encoded Vertex Shader size doesn't match specified size
body: <p>I am working on a game engine using DirectX 11 and am having trouble getting shaders to encode properly. I am precompiling shaders to .csh files and creating shaders with the byte codes.</p>
  
  <p>I get this error when I try to create any shader, but for this example I will use my PassThrough vertex shader.</p>
  
  <pre><code>D3D11 ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE]
  </code></pre>
  
  <p>The Shader:</p>
  
  <pre><code>#include "../VertexLayouts.hlsli"
  // structs in included file
  struct PASS_THROUGH_VS
  {
      float3 pos : POSITION;
      float2 texCoord : TEXCOORD;
  };
  
  struct PASS_THROUGH_PS
  {
      float4 pos : SV_POSITION;
      float2 texCoord : TEXCOORD;
  };
  
  
  PASS_THROUGH_PS main( PASS_THROUGH_VS input )
  {
      PASS_THROUGH_PS output = (PASS_THROUGH_PS)(0);
      output.pos = float4(input.pos, 1);
      output.texCoord = input.texCoord;
      return output;
  }
  </code></pre>
  
  <p>with these settings:
  <a href="https://i.stack.imgur.com/rVVx5.png" rel="nofollow noreferrer">PassThrough_PS properties</a></p>
  
  <p>In Renderer.h</p>
  
  <pre><code>#include "Vertex Shaders\PassThrough_VS.csh"
  </code></pre>
  
  <p>In Renderer.cpp</p>
  
  <pre><code>HRESULT hrReturn;
  
      hrReturn = CreateVertexShader(&amp;PassThrough_VS, sizeof(PassThrough_VS), Pass_Through_VS);
      if (FAILED(hrReturn)) {}
          //return hrReturn;
  
  HRESULT CRenderer::CreateVertexShader(const void* ptrByteCode, SIZE_T szByteCodeLength, eVertexShaderType type)
  {
      HRESULT hrReturn;
      tVertShader newShader = {};
      hrReturn = D3Device-&gt;CreateVertexShader(&amp;ptrByteCode, szByteCodeLength, nullptr, &amp;(newShader.m_id3dShader)); // WHERE ERROR OCCURS
      if (FAILED(hrReturn))
          return hrReturn;
      newShader.m_ptrByteCode = ptrByteCode;
      newShader.m_szByteCodeLength = szByteCodeLength;
      D3VertexShaders[type] = newShader;
      return hrReturn;
  }
  </code></pre>