I am developing the application that uses DirectX for graphics rendering. I have to point out that I am not using XNA or SlimDX, although I probably should. However, I did not know this at the project launch, and now it’s too late as it would take a lot of time to convert to any of these.
That said, I need to deploy the application to users. In my project, I have referenced the following assemblies:
- Microsoft.DirectX
- Microsoft.DirectX.Direct3D
- Microsoft.DirectX.Direct3DX
I only need these assemblies, nothing else. The users are required to have DirectX installed on their computers as a prerequisite. Therefore, I found including these DirectX DLLs to my application folder or GAC unnecessary.
I am having problems with some environments while other work perfectly. I’ve traced the issue to whether DirectX assemblies are registered in %windir%\assembly. If there are DirectX assemblies listed here, the application runs. If there are not – it fails to launch.
The problem is that even though DirectX is installed on all computers (dxdiag works, DirectX files are listed in it), some of them do not have these assemblies listed in there. When this happens, the application fails with System.IO.FileNotFound exception:
Could not load file or assembly ‘Microsoft.DirectX.Direct3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
For instance, if the latest stand-alone installer is downloaded from Microsoft website and installed, the assemblies are registered. I am not sure about the case when they do not get installed, but it happens. Often.
My questions:
- Why does DirectX sometimes register these assemblies and sometimes do not?
- What is the proper way to reference DirectX assemblies from within
the application?
I’m not surprised that you’re seeing these issues. You’re relying on an extremely old, discontinued, and no-longer-supported API. The latest runtime installers will still install the assemblies for compatibility purposes, but they’re not included by default because they don’t expect anyone to use them.
Honestly, they’re really old (like, 10 years old), they have numerous known bugs and issues that will never be fixed, and there are perfectly acceptable replacements out there. You should either switch to one of them or resign yourself to dealing with issues like this for as long as you continue to support your app.