Ndech
Ndech

Reputation: 965

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 ?

Upvotes: 3

Views: 1937

Answers (2)

ManIkWeet
ManIkWeet

Reputation: 1338

It's old but I respond anyway: The default encoding of new visual studio text files is UTF-8 with BOM. That means that the first 3 characters of your file are 
Those characters are "illegal"

Source:
http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8

Upvotes: 5

Ndech
Ndech

Reputation: 965

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.

Upvotes: 3

Related Questions