DirectX project fails to load shader at runtime

I created a new DirectX project and compiled a shader with MGCB.
However, at runtime I get the below error when trying to load the effect:

  • ‘This MGFX effect was built for a different platform!’

This is from my project file:
OutputType: WinExe
TargetFramework: net5.0-windows
MonoGamePlatform: Windows

MGCB seems to be passing the correct platform switch: /platform:Windows
I’m not sure what else to check ?

PackageReference Include=“MonoGame.Framework.WindowsDX” Version=“”
PackageReference Include=“MonoGame.Content.Builder.Task” Version=“”

Maybe you’re loading the wrong effect file, one that was built for OpenGL. If you delete all temporary folders (obj + bin), and then only build for DX, there should be no chance to have multiple versions of the same effect.

It seems the Effect is being compiled correctly, however, somehow I’m binding to the OpenGL version of MonoGame rather than DX version.

If I’m reading this correctly from the compiled Effect file:
MGFX v9 Platform 1 (DX)

But the Profile ID on the Shader is 0 (OpenGL)

Even though I’m linking to the WindowsDX package

However, I am referencing a .Net Standard2.1 Library which IS referencing the DesktopGL package

So it seems I’m somehow getting the DesktopGL package reference from the library rather than the WindowsDX package that I’m referencing in the .exe

It could be your drivers, they might get an update if you did update your drivers by hand they are automatically removed… maybe considder using the auto detection tools available for your gpu vendor.

Thanks Sebastian, but it seems to be a misunderstanding on my part of how to target multiple platforms.

My library projects were set as .Net standard 2.1 targeting DesktopGL and my main ‘Platform’ projects targeted Android / DesktopGL / DirectX. My understanding was that the Platform dependencies would be used, however, the bin folder for the Platform builds seems to have the DesktopGL version of MonoGame.Framework.dll rather than DirectX / Android / etc. version

Changing all my projects to .Net 5 + windows and referencing the DirectX version of MG solved the issue, It’s just not ideal.