I've recently been working on a small helper for creating and using compute shaders in C# along with Monogame/XNA. My end goal is simply to have compute shaders working in C#.

My main issue is as such:

   var result = SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile(filepath, "CSMain", "cs_5_0", ShaderFlags.Debug);
   if (result.ResultCode.Failure)
      throw new Exception($"HLSL Compilation failed with the code: [{result.ResultCode.Code}] and message: [{result.Message}]");
   shader = new SharpDX.Direct3D11.ComputeShader(device, result.Bytecode);

Calling the constructor on the ComputeShader class throws the error: "HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect." (Of type SharpDXException). The device is obtained via Microsoft.Xna.Framework.Graphics.GraphicsDevice.Handle casted to a D3D11 Device.

Call Stack: Call Stack

Anyone know how to fix this? Or is this just something I'll have to find some new way of doing?

The fact that I went down the Monogame-DirectX + SharpDX route is largely incidental, but I don't seem to have many options - something like Vortice.Windows, which aims to replace the now abandoned SharpDX, doesn't appear to have compute shader support. While I wouldn't mind using OpenGL, and would be happy with being recommended working .Net Core OpenGL binding libraries (Vulkan would probably be way over my head), that type of question isn't accepted here, but I'm aware it may be the better option.


1 Answer 1


The device from Microsoft.Xna.Framework is Direct3D 9, which isn't going to support Direct3D 11 features.

Why not use SharpDX to create the device so you know it's Direct3D 11?

  • \$\begingroup\$ Despite the inline documentation seeming to indicate it being DX11 capable you were correct, thank you. \$\endgroup\$
    – sfbea
    Aug 2, 2020 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .