I'M reading the book "Beginning C# Game Programming by Ron Penton". The book is instucting me to create a small framework for a game, the problem is, the book was written for VS 2002 and I'M using VCs 2008 express. I'M instructed to add references to the project, two of which I can't find. Microsoft.DirectX & Microsoft.DirectX.3D.

Here's the code and the errors I'M getting

Error 1 The type or namespace name 'DirectX' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\ 12 17 02-VCSFrame1

Error 2 The type or namespace name 'DirectX' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\ 13 17 02-VCSFrame1

Error 3 The type or namespace name 'Device' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Owner\Documents\Visual Studio 2008\Projects\02-VCSFrame1\02-VCSFrame1\ 25 3 02-VCSFrame1

// Beginning C# Game Programming
// (C)2004 Ron Penton
// Chapter 6
// Demo 2 - Visual C# Framework

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace MyDirect3DProject
{
	/// <summary>
	/// This is the main class of my Direct3D application
	/// </summary>
	public class MainClass : Form
	{
		/// <summary>
		/// The rendering device
		/// </summary>
		Device device = null;
		
		public MainClass()
		{
			this.ClientSize = new System.Drawing.Size(640, 480);
			this.Text = "Direct3D Project";
		}
		
		public bool InitializeGraphics()
		{
			try {
				// Now let's setup the Direct3D stuff
				PresentParameters presentParams = new PresentParameters();
				presentParams.Windowed   = true;
				presentParams.SwapEffect = SwapEffect.Discard;
				
				// Create the device
				device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
				
				// Setup the event handlers for the device
				device.DeviceLost     += new EventHandler(this.InvalidateDeviceObjects);
				device.DeviceReset    += new EventHandler(this.RestoreDeviceObjects);
				device.Disposing      += new EventHandler(this.DeleteDeviceObjects);
				device.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing);
				
				return true;
			} catch (DirectXException) {
				return false;
			}
		}
		
		protected virtual void InvalidateDeviceObjects(object sender, EventArgs e)
		{
		}
		
		protected virtual void RestoreDeviceObjects(object sender, EventArgs e)
		{
		}
		
		protected virtual void DeleteDeviceObjects(object sender, EventArgs e)
		{
		}
		
		protected virtual void EnvironmentResizing(object sender, CancelEventArgs e)
		{
		}
		
		/// <summary>
		/// This method moves the scene
		/// </summary>
		protected virtual void FrameMove()
		{
			// TODO : Frame movement
		}
		
		/// <summary>
		/// This method renders the scene
		/// </summary>
		protected virtual void Render()
		{
			if (device != null) {
				device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
				device.BeginScene();
				
				// TODO : Scene rendering
				
				device.EndScene();
				device.Present();
			}
		}
		
		/// <summary>
		/// Our mainloop
		/// </summary>
		public void Run()
		{
			// While the form is still valid, render and process messages
			while (Created) {
				FrameMove();	
				Render();
				Application.DoEvents();
			}
		}
		
		protected override void OnPaint(PaintEventArgs e)
		{
			this.Render();
		}
		
		protected override void OnKeyPress(KeyPressEventArgs e)
		{
			base.OnKeyPress(e);
			if ((int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape) {
				this.Close(); 
			}
		}
		
		/// <summary>
		/// The main entry point for the application
		/// </summary>
		static void Main()
		{
			using (MainClass mainClass = new MainClass()) {
				if (!mainClass.InitializeGraphics()) {
					MessageBox.Show("Error while initializing Direct3D");
					return;
				}
				mainClass.Show();
				mainClass.Run();
			}
		}
	}
}

Thanks for any and all replies.

Dani AI

Generated

Short answer: those missing types come from the old Managed DirectX (MDX) assemblies — not from core .NET — so they won’t appear in a fresh Visual C# install unless the legacy DirectX pieces are present. MDX is a deprecated, legacy wrapper and Microsoft now recommends more modern paths for managed game work. (learn.microsoft.com)

If the goal is to run Ron Penton’s book examples unchanged, install the legacy DirectX SDK and then add the managed assemblies by browsing to the DirectX-for-managed-code folder (for example the "DirectX for Managed Code" or "Managed DirectX" folder under Windows) and selecting Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll. After adding them, set the project to target x86 (MDX is 32‑bit only) and use .NET 2.0/3.5 — MDX is not compatible with .NET 4.0+ without workarounds. These steps (browse-to-folder + x86 target) are the usual fix when the assemblies are not listed in the Add Reference dialog. (stackoverflow.com)

Longer-term advice: don’t start new projects on MDX. For XNA-style managed development use MonoGame; for low-level Direct3D access from modern .NET use maintained bindings such as Vortice.Windows. SharpDX and SlimDX were popular alternatives historically, but SharpDX is archived and SlimDX is legacy — prefer actively maintained projects for new work. (monogame.net)

Practical troubleshooting checklist: (1) confirm the legacy SDK installed successfully, (2) use Add Reference → Browse and point to the Managed DirectX folder or the GAC, (3) set Platform target = x86, (4) lower the target .NET framework to 3.5/2.0 if you hit runtime/build issues, and (5) consider porting to MonoGame/Vortice if you plan to continue development on modern Windows. Mentioning because their pointer to checking the references is on the right track — the steps above fill in the missing details.

I'M reading the book "Beginning C# Game Programming by Ron Penton". The book is instucting me to create a small framework for a game, the problem is, the book was written for VS 2002 and I'M using VCs 2008 express. I'M instructed to add references to the project, two of which I can't find. Microsoft.DirectX & Microsoft.DirectX.3D.

Thanks for any and all replies.

Hello

First thing you should check is if you have "Microsoft.DirectX" in Add reference(.Net tab).
If not you can download it from: .
After installing it you should find the reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.