x


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 namespaceSystem.IO'. Are you missing an assembly reference?
  • error CS0234: The type or namespace name Unix' does not exist in the namespaceMono'. 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);
       }

*/
    }
}
more ▼

asked Jun 27 '11 at 07:02 AM

Amiad gravatar image

Amiad
38 4 4 8

I have same problem, anyone know reply? I have windows 8

Apr 01 '12 at 02:21 AM penna91
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Apr 08 at 08:58 AM

Inhuman Games gravatar image

Inhuman Games
31 1

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Apr 01 '12 at 03:04 AM

Bunny83 gravatar image

Bunny83
46.9k 12 50 210

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4374
x233
x183
x4
x2

asked: Jun 27 '11 at 07:02 AM

Seen: 1071 times

Last Updated: Apr 08 at 08:58 AM