DirectX and .NET

With the DirectX SDK (June 2010) release and the addition of support for Visual Studio 2010, I’ve been seeing a lot of questions of the form:

How do I create a DirectX .NET application in Visual Studio 2010? I can’t find Microsoft.DirectX to add to my project but I have the DirectX SDK (June 2010) release installed.

As with many seemingly simple questions on a technical topic, this one is actually quite complex.

Back in the days of DirectX 7 and DirectX 8, there was support included for using DirectX from Visual Basic. While most developers used DirectX APIs via C and C++, there was intense interest in the hobbyist community to access this technology. Thus the focus on enabling Visual Basic developers. When working on DirectX 9, Visual Basic had become unified with the .NET family of languages and thus Managed DirectX 1.1 was created (with a great deal of individual passion and effort from Tom Miller and others on the DirectX team at the time). It was designed for the .NET 1.1 Runtime, and include managed wrappers for the whole family of DirectX technology: Direct3D 9, D3DX9, DXDIAG, DirectDraw, DirectInput, DirectPlay, DirectSound, and a simple wrapper for DirectShow. The focus shifted from the Visual Basic language to C#, although VB .NET could still be used.

Note: The DirectX 7 and 8 Visual Basic 6.0 support I mention here is no longer available as of Windows Vista. It was part of DirectX 9.0c and was included with Windows XP Service Pack 2&3, Windows Server 2003 Service Pack 1 & 2, and Windows XP Professional x64 Edition.

With the release of .NET 2.0, there was an effort to update Managed DirectX to use the new constructs and in 2005 there was a Managed DirectX 2.0 Beta included as part of the DirectX SDK. As this effort was underway, a major reorganization at Microsoft took place and when the dust settled, the relatively small team that had been working on this technology suddenly found themselves as the seed of an entirely new effort around .NET gaming development: XNA Game Studio. The Managed DirectX 2.0 project was shelved, and all the effort focused on this new more comprehensive end-to-end solution for the indie game developers targeting Windows, Xbox 360, Zune, and eventually Windows Phone 7.

Managed DirectX 1.1 as it stands today is deprecated. It was last updated in April 2006 to match that version of D3DX9, while the Managed DirectX 1.1 documentation was last updated in August 2005. The last DirectX SDK to include the samples and documentation for Managed DirectX 1.1 was August 2006. Since that time, we’ve continued to include the Managed DirectX 1.1 assemblies in the DirectX SDK Developer Runtime, the DirectSetup REDIST folder, the DirectX End-User Runtime package, and the DirectX End-User Runtime Web Installer to simplify legacy deployment and support existing applications that relied on it. This last support for Managed DirectX 1.1 deployment is likely to be removed in a future DirectX SDK update.

At this point, Managed DirectX 1.1 is really beginning to show it's age.

  • Since the last version of D3DX9 supported by Managed DirectX 1.1 is April 2006, it makes use of a very outdated version of the HLSL compiler.
  • The Managed DirectX 1.1 assemblies are 32-bit only, so you cannot use them from an x64 native .NET application (/platform:anycpu on a Windows x64 system). You must build with /platform:x86 and stay within the limits of the 2 GB memory space of 32-bit applications.
  • The assemblies only support the legacy DirectX API set, with no support for Direct3D9Ex, Direct3D 10.x, Direct3D 11, Direct2D, DirectWrite, DXGI, D3DX10, D3DX11, XAUDIO2, XACT, XINPUT, etc.
  • Since Managed DirectX 2.0 was never released in production form, the Managed DirectX 1.1 assemblies still reflect .NET 1.1 design principles and does not support or make use of .NET 2.0 constructs.
  • Managed DirectX 1.1 while compatible with .NET 2.0 (and the .NET 3.0 and .NET 3.5 extensions of the 2.0 runtime), is not compatible with .NET 4.0

The last bullet here is the heart of the issue I started out with in this post. The Visual Studio 2010 toolset only supports developing .NET 4.0 applications, and therefore Managed DirectX 1.1 as a .NET 1.1 technology is not supported by Visual Studio 2010. BTW, it is possible to use the Visual Studio 2010 IDE to build .NET 2.0 applications using older toolsets through multi-targeting, but this is really using legacy tools which do work with .NET 1.1 era assemblies.

The modern version of the DirectX SDK is designed for C/C++ native developers. If you are looking for .NET solutions for using DirectX technology, there are many options available although the choice of solution depends on your specific needs:

  • XNA Game Studio is the solution aimed directly at indie game developers looking to create Direct3D games on Windows, Xbox 360, Zune, and Windows Phone 7. It has some limitations (requires /platform:x86, no support for DirectX 10.x or DirectX 11, more focused DirectX API support, no support for Windows Store or Windows phone, content pipeline only works with VS 2010), but includes numerous tools and a vibrant developer community. Those original hobbyist developers Tom Miller wanted to help are very well served by this product, as is the professional and indie game developer looking for a complete solution for writing .NET games. Monogame is also an open-source alternative to XNA Game Studio, and Unity3D is a commercial alternative.
  • For a developer using the Windows Presentation Foundation but wants to use the new DirectX 11 APIs, the Windows API Code Pack provides managed assemblies for Direct3D 10.1, Direct3D 11, Direct2D, DirectWrite, DXGI, and the Windows Imaging Library  (WIC) along with many other Windows 7 features. The latest version supports .NET 4.0, and x64 native “anycpu” applications. Note you still need to install the DirectX SDK to get the HLSL compiler (FXC.EXE) tool.
  • For developers who are invested in Managed DirectX 1.1 but are looking for updates to address the limitations I note above for Win32 desktop applications, the open source SlimDX library is designed to mimic Managed DirectX 1.1 for just this purpose. It includes support for x64 native “anycpu” applications, includes modern DirectX support, and is compatible with the .NET 4.0 runtime.
  • SharpDX another option for C# and is currently the preferred solution for 'modern' Microsoft platforms including Windows Store and Windows phone 8.
  • If you are a media developer using DirectShow and want a more complete solution than the simple Managed DirectX 1.1 wrapper, the open source library may be useful to you, although it doesn’t yet appear to have been updated to be .NET 4.0 compatible.

If these solutions don’t work for you, you can always write your own managed wrapper using standard native interop constructs or use Managed C++/CLI to write the DirectX portion of your application in C/C++ using the DirectX SDK. The Windows Presentation Foundation D3DImage class can be a useful way to do this interop, although the use of Direct3D9Ex on Windows Vista and Windows 7 can cause some problems with components like D3DX9 which you should watch out for.

.NET 1.1 Framework: Note that the .NET 1.1 Framework is not supported on either Windows 7 or Windows 8.x.

Win2D: Another option to consider is ShawnHar's latest project for using Direct2D/DirectWrite from C# or C++/CX.

Comments (11)

  1. Alexandre Mutel says:


    I would like to add to your list a new "pure" managed DirectX .Net API called SharpDX (…/sharpdx) which is a real "AnyCpu" API, currently supporting DXGI 1.0/1.1, Direct3D10, Direct3D10.1, Direct3D11, Direct2D1, DirectWrite, DirectSound, XAudio2, XAPO, and running under .NET 4.0.

    In fact, none of the API you have listed above are real "AnyCpu" library, as they are built using C++/CLI and thus require an installer to install x86 and x64 specific assemblies to the GAC. SharpDX doesn't have this restriction, using a genuine way to avoid any C++/CLI while still achieving comparable performance. It means for example that SharpDX assemblies are easily obfuscatable (Almost all Obfuscators are not able to obfuscate C++/CLI assemblies).

    Also, SharpDX API is entirely generated automatically from DirectX SDK headers, which is interesting to easily support future DirectX APIs.

  2. neutrality says:

    I thought one of the benefits of COM is language neutrality: a COM component written in any language can be consumed by any language that can be a COM client (which includes .NET languages).

    Since the DirectX APIs are COM-based, shouldn't they be directly usable from .NET languages? Is there a fundamental issue that prevents this?

  3. Modern DirectX uses a "COM-like" implementation which isn't truely compliant with COM. For example, the refcounting on Direct3D 10.x/11 objects are all 'weak references' which dangle when the device is destroyed. There are some cases where you can do QueryInterface, but it is not fully robust.

    In any case, the problem isn't really the base API. the problem is that you need a fair amount of infrastructure to effectively use the Direct3D API: shaders, GPU resources, texture and mesh loading, etc. We have C++ solutions in the DirectX SDK for many of these things, and the XNA Game Studio product includes C# solutions.

  4. Azure' says:

    Wow, thanks Alexandre!

  5. Vincenzo says:

    There is also a very nice Dx11 .NET wrapper downloadable at

  6. rasya says:

    are 32bit operating system compatible with direct x? If compatible, which direct x product i must use?

  7. RE: RASYA

    "DirectX" the technology supports both x86 and x64 platforms. XNA Game Studio and Managed DX 1.1 work on both x86 and x64 platforms, but only work on x64 platforms with the /platform:x86 flag as I note above.

    Can you try to clarify your question?

  8. rj jansky says:

    New to this DirectX game by way of a broken build.  This is legacy code.  The code in question references the Microsoft.DirectX.DirectInput object which our working machines find under Mircrosoft.NETDirectX for Managed Code.  The new machine is not finding this folder and I'm reading a bunch trying to figure out what to do about it.  Any suggestions?  Working and broken builds are happening on Windows 7 with VS2005.  Working is a 32bit Win 7 and broken is a 64bit Win 7 (we're finally moving, or attempting, to move to a 64bit environment).

  9. As noted above, the legacy DirectX Managed assemblies require you have .NET 1.1 installed, and then run the DirectX End-User Runtime (DXSETUP) to get the assemblies installed. You are probably missing .NET 1.1, which isn't officially supported on Windows 7+.

    You should consider looking at SlimDX which is intended to be a modern supported version of the original DirectX Managed assemblies design. SharpDX is more recent, but is not an identical API.

  10. dustubeaq says:

    OpenGL rocks.

  11. SharpDX works fine but I find it quite difficult to use because it redefines all the functions, interfaces, constants, names, and it’s sometimes difficult to determine what the “Bitmap” class corresponds to (WIC? D2D1? etc.).
    So, for what it’s worth, I have created a .NET project open source project “DirectN” that contains “pure” .cs p/invoke code for DirectX 9 to 12, DXGI, WIC, Direct2D, Direct Write, Media Foundation, WASAPI, CodecAPI, GDI, Spatial Audio, DVD, Windows Media Player, etc.
    That’s around 6000 .cs files 🙂 Note it still contains errors of course since it’s quite a big thing.

Skip to main content