convert c# code for unity return errors

I try to run c# in unity but I got errors:

  • error CS0234: The type or namespace name Pipes' does not exist in the namespace System.IO’. Are you missing an assembly reference?
  • error CS0234: The type or namespace name Unix' does not exist in the namespace Mono’. Are you missing an assembly reference?

How I can to convert the code to something that run on Unity?
code:

using System;
using System.IO;
using System.IO.Pipes;

using System.Net;
using System.Net.Sockets;
using System.Xml;
#if __MonoCS__
using Mono.Unix;
#endif

namespace Mumble {
	public class Mumble {
		protected NamedPipeClientStream pipe;
		protected StreamReader sr;
		protected StreamWriter sw;

		public Mumble() {
#if __MonoCS__
			Socket s = new Socket(AddressFamily.Unix, SocketType.Stream, 0);
			UnixEndPoint ue = new UnixEndPoint(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/.MumbleSocket");
			s.Connect(ue);
			NetworkStream pipe = new NetworkStream(s);
#else
			pipe = new NamedPipeClientStream("Mumble");
			pipe.Connect();
#endif

			sr = new StreamReader(pipe);
			sw = new StreamWriter(pipe);
		}

		private bool OutputStringReply() {
			String line;
			while ((line = sr.ReadLine()) != "") {
				Console.WriteLine(line);
			}
			return true;
		}

		private bool ReadReply() {
			bool reply;
			using (XmlReader xr = XmlReader.Create(sr)) {
				xr.MoveToContent();
				xr.ReadToDescendant("succeeded");
				reply = xr.ReadElementContentAsBoolean();
			}
			return reply;
		}

		public bool Mute(bool state) {
			sw.WriteLine("<self mute='{0}' />", state);
			sw.Flush();

			return ReadReply();
		}

		public bool Deaf(bool state) {
			sw.WriteLine("<self deaf='{0}' />", state);
			sw.Flush();

			return ReadReply();
		}

		public bool Focus() {
			sw.WriteLine("<focus />");
			sw.Flush();

			return ReadReply();
		}

		public bool OpenUrl(String url) {
			Uri u;
			Uri.TryCreate(url, UriKind.Absolute, out u);
			sw.WriteLine("<url><href>{0}</href></url>", u);
			sw.Flush();

			return ReadReply();
		}

		public String QueryUrl() {
			sw.WriteLine("<url />");
			sw.Flush();

			String reply;
			using (XmlReader xr = XmlReader.Create(sr)) {
				xr.MoveToContent();
				xr.ReadToDescendant("href");
				reply = xr.ReadString();
			}
			return reply;
		}

/*
		public static void Main(String[] args) {
			Mumble m = new Mumble();
			m.Deaf(true);
		}

*/
	}
}

Just take a look on the MonoCompatibility page to see what namespaces and / or classes are supported on which platforms. The page is huge and my take a while to fully load. You your browsers search function to fine a specific namespace.

The error speaks for itself. Those two namespaces are not supported in Unity, so you can’t use this code (which wasn’t written for Unity) in Unity. Yes you can find alternatives, but that’s not our job…

For “using System.IO.Pipes” you first must change this setting:

Project Settings->Player->Api Compatibily Level: set this to “.Net 2.0” (not subset).

Pipes and other rarely used stuff are removed by default, probably as a disk space optimization.