System.Media.Soundplayer not a namespace? (mac) - c#

I'm trying to play sounds in c#, and none of the System.Media namespaces are working, instead giving the error:
Error CS1069: The type name 'SoundPlayer' could not be found in the namespace 'System.Media'
I'm am doing using System.Media; but it still gives the error.

The SoundPlayer class provides a simple interface for loading and playing a .wav file. The SoundPlayer class supports loading a .wav file from a file path, a URL, a Stream that contains a .wav file, or an embedded resource that contains a .wav file.
It is for .Net Framework and not for .Net Core. Essentially, all of the sound-playing functionality that was available in .NET Framework was Windows-specific; therefore none of it made it into .NET Core.
For more information you can check SoundPlayer Class in Microsoft .Net Framework documentation.

Related

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

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();
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.

HttpUtility not recognised in .Net 4.5

I Developed a WinForm application in with the target framework set to .net 4.0, now I wish to add to a project that has it's target framework set to .net 4.5. After I added the 4.0 WinForm application to my 4.5 project I keep getting the an error on my HttpUtility object.
data += "&batch_data=" + HttpUtility.UrlEncode(batch, System.Text.Encoding.GetEncoding("ISO-8859-1"));
"The name 'HttpUtility' does not exist in the current context"
I did include the System.Web namespace where the HttpUtility is located.
Visual Studio Error:
CS0234 The type or namespace name 'HttpUtility' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The problem is somewhere else.
As you can see in MSDN the HttpUtility class is present in System.Web in .NET Framework 4.5.
You're probably targeting the Client Profile: target the full framework in Project Properties. Otherwise:
either you did not add the right using statement using System.Web;
or you did not add the reference to System.Web.dll in the project.
WebUtility
You also have another possibility: Use the WebUtility class.
The WebUtility class is recommended by Microsoft itself and should be used outside of web applications.
Like the HttpUtility class it also provides you with the possibility to encode and decode URLs.
This way you don't have the problems with importing the library into your project or setting some specific profiles.
From the Documentation (Source)
The HttpUtility class is used internally by the HttpServerUtility class, whose methods and properties are exposed through the intrinsic ASP.NET Server object. Additionally, the HttpUtility class contains encoding and decoding utility methods that are not accessible from the Server.
To encode or decode values outside of a web application, use the WebUtility class.
The HttpUtility class exists from .NET 1.1, so I think it is not possible for regular projects to 'not see it', as long as you have included a reference to System.Web.
You might be using a PCL (Portable Class Library), which uses a stripped down version of the framework that is supported on the platforms you selected, like Windows Store apps, Windows Phone, Silverlight, etc.
I hope this link will help you.
http://msdn.microsoft.com/en-us/library/system.web.httputility(v=vs.110).aspx
Dot net framework 4.5 support HttpUtility as it is under System.Web namespace.
Also adding a System.Web reference, without System.Web.Extensions reference into your project. If it doesn't work remove the existing and add new reference of System.Web into project. Also check which framework it is targeting it should be .NET Framework 4 or 4.5 without Client.
I encountered this issue in .net 4.5.2 (using VS2019). I did check that I was using full framework and I also tried explicitly declaring System.Web in a using statement, though VS complains that the using clause is not needed.
System.Web.Utility appears to have been replaced by System.Net.Webutility

System.IO.Compression.FileSystem.dll in c# program

I' like to use the dll System.IO.Compression.FileSystem.dll in my project
the .net framework version is 4.5 and the os is 64. The problem is that the dll is not found.
What is the solution?
The namespace is not the same as the dll name (assembly name). from the MSDN page you linked
Namespace: System.IO.Compression
Assembly: System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)
So the namespace you need to include is System.IO.Compression not System.IO.Compression.FileSystem. Take off the FileSystem part from your using statement and it will solve your problem.
If people are down-voting me because the OP said "The problem is that the dll is not found." I think the OP is not using the correct word choice, if the problem really was that the DLL could not be found there would be a exclamation point by the assembly name which the original screenshot does not have
See the original image below
(click for larger view)
Compare that to my screenshot I created that would show up if the DLL really was not found, note the exclamation point I have that the original screenshot does not.
in the System.IO.Compression there's no such class as FileSystem check it out the link on the msdn
the classes available are:
DeflateStream Provides methods and properties for compressing and decompressing streams by using the Deflate algorithm.
GZipStream Provides methods and properties used to compress and decompress streams.
ZipArchive Represents a package of compressed files in the zip archive format.
ZipArchiveEntry Represents a compressed file within a zip archive.
ZipFile Provides static methods for creating, extracting, and opening zip archives.
ZipFileExtensions
if your goal is to use compression of file or stream use the GZipStream class.
However remove the FileSystem from the using statement:
using System.IO.Compression;
Anyway as Joe Enos has pointed out classes from the Compression namespace have been taken out the Client Profile from the framework 4.5
Below the Version Information from the msdn about the GZipStream:
.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client Profile
Supported in: 4, 3.5 SP1
A new nuget package is coming out. Check this out :)
https://www.nuget.org/packages/System.IO.Compression.ZipFile
Adding reference to System.IO.Compression.dll solved this issue for me.

How to use XDocument class in Mono

I'm trying to use XDocument class inside a Unity3D project on Windows 7.
I did the following:
added the reference System.Xml.Linq to the Mono project.
included the namespace:
using System.Xml.Linq;
set the target framework to: Mono/.NET 3.5
clean and rebuild the project
But still Unity3D complains about it. Here's the error output in the console:
Assets/Scripts/Editor/RoadManager/RoadManager.cs(3,18): error CS0234:
The type or namespace name `Linq' does not exist in the namespace
`System.Xml'. Are you missing an assembly reference?
Any idea?
This has been discussed many times before, but few of these answers are complete.
As has been said before, Unity3d only supports up to .NET version 2.0, and it seems System.Xml.Linq was introduced in .NET 3.5, besides the fact that it is not listed on the Unity3d compatibility list anywhere.
The only things to try are to set the Mono API compatibility level to 2.0 (Menu: Edit > Project Settings > Player and look in the Other Settings panel), but it seems that that was a mistaken solution for Linq2SQL.
Another possible solution is to add the DLL yourself into the Unity Editor as shown:
Try dragging the C:\Program Files
(x86)\Unity\Editor\Data\Mono\lib\mono\2.0\System.Xml.Linq.dll file
into the unity project window like you would a texture or other game
asset.
If none of these yield ANY luck for you, then I'm afraid you are out of luck.
Unity3D supports .Net 2.0 only, so setting compatibility to .net 3.5 in MonoDevelop/Visual Studio will not work. You will have to make do without the class. This shows what library classes are available:
http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html
See also this post in UnityAnswers: http://answers.unity3d.com/questions/46039/can-not-reference-systemxmllinq.html

Referencing OpenWebKitSharp to use WebKit in C#

I am trying to reference OpenWebKitSharp, the C# library for WebKit. However, I keep getting an error on compiling: "The type or namespace WebKitBrowser does not exist in the namespace WebKit".
I am trying to follow the directions at http://code.google.com/p/open-webkit-sharp/ but I do not know what this means:
Copy the contents of the cairo build to your debug/release folder.
What is a cairo build? Why do I keep getting this error even though I am referencing both WebKit.Interop and OpenWebKitSharp?
On a similar note, is there a good site for documentation about the OpenWebKitSharp library?
If you are using .Net Framework Client Profile, change it to .Net Framework 4

Categories

Resources