I can't find the System.Media namespace in Visual Studio 2019

5.4k views Asked by At

Edit - ANSWER: I found the solution thanks to @LexLi and @Amy; I accidentally created a .NET Core console application instead of .NET Framework. Once I remade it as a .NET Framework app it had "System.Media" available.

I'm relatively new (only a few weeks in) to learning C#, but I'm trying to make a console application text game, and I have a typewriter method I'm using to print messages to the display.

public static void typewriter(string s)
{
    // This method types strings out slowly.
    for (int i = 0; i < s.Length; i++)
    {
        Console.Write(s[i]);

        Thread.Sleep(50);
    }
}

I want to add a sound when each character is typed (I have the typewriter sound already). I saw some people recommend the SoundPlayer class located in System.Media. It would look something like this:

SoundPlayer typewriter = new SoundPlayer();
typewriter.SoundLocation = Environment.CurrentDirectory + "/typewriter.wav";

My problem is, I don't seem to have access to System.Media

If I type using System.(et cetera), Intellisense does not show Media as an available option. I am using Visual Studio 2019 and have .Net Framework Version 4.8 something

How can I get access to System.Media?

Here's a photo with some info to show my .Net framework and that Visual studio doesn't recognize SoundPlayer(); system media not found or not containing SoundPlayer

1

There are 1 answers

4
AudioBubble On

Check MSDN for documentation on that namespace. Identify which assembly its located in. Then add a reference to that assembly.

Google "MSDN system.media".. Pick a class from that namespace. I'll use SoundPlayer.

The documentation says that class is located in Assemblies: System.dll, System.Windows.Extensions.dll.

So add a reference to one of those assemblies.