Search code examples
c#directxhlsldirectx-11sharpdx

Impossible to compile hlsl shaders after updating to Sharpdx 2.6.2


I have a C# project that used SharpDX 2.5.0 and everything was working fine. I moved to the newest stable release of SharpDX, 2.6.2. My project compile fine but fails at runtime because it cannot compile the shaders. I'm using this line of code :

var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "Base_VS", "vs_4_0");

No matter what the actual content of the shader file is, it fails with the following error :

path/to/my/shader.hlsl(1,1): error X3000: Illegal character in shader file

I thought it was related to the UTF-8 encoding of the file, but trying various encoding did not solve the problem. Has anyone else encountered a similar problem or has a suggestion ?


Solution

  • I finally found a solution. In case someone encounters the same situation, here is the workaround I found :

    • It was really an encoding problem. For some reason the format of my shader files was not compatible anymore, and for some reason just changing the encoding in Visual studio did not solve the problem. There seemingly was still some invisible character in the beginning of the file (maybe the BOM?).
    • Recreating the file from scratch (from notepad) worked.