Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

The type or namespace 'Semaphore Slim could not be found

Discussion in 'Scripting' started by eco_bach, Feb 1, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Having similar issue to this

    http://stackoverflow.com/questions/15658318/using-semaphore-in-c-sharp

    I have determined that I have .NET 4.6.4 Preview or greater on my machine.

    This is a Unity C# project! If I open the source project in VS I don't see the error and project properties shows I am targeting .Net framework 4. So I guess my question is more to do with the way Unity handles .net classes. Confused whether I should be trying to fix this WITHIN VS in the Solution explorer or...?

    My understanding is that System.Threading contains the SempahoreSlim class.

    I am using source code from this example
    https://www.codeproject.com/articles/488668/csharp-tcp-server

    Just a partial code listing (first 50 lines of TcpServer)

    Code (csharp):
    1.  
    2.   using System;
    3.   using System.Collections.Generic;
    4.   using System.ComponentModel;
    5.   using System.Net;
    6.   using System.Net.Sockets;
    7.   using System.Text;
    8.   using System.Threading;
    9.    
    10.   namespace tcpServer
    11.   {
    12.   public delegate void tcpServerConnectionChanged(TcpServerConnection connection);
    13.   public delegate void tcpServerError(TcpServer server, Exception e);
    14.    
    15.   public partial class TcpServer : Component
    16.   {
    17.   private List<TcpServerConnection> connections;
    18.   private TcpListener listener;
    19.    
    20.   private Thread listenThread;
    21.   private Thread sendThread;
    22.    
    23.   private bool m_isOpen;
    24.    
    25.   private int m_port;
    26.   private int m_maxSendAttempts;
    27.   private int m_idleTime;
    28.   private int m_maxCallbackThreads;
    29.   private int m_verifyConnectionInterval;
    30.   private Encoding m_encoding;
    31.    
    32.   private SemaphoreSlim sem;
    33.  
    34.  
    35.   private bool waiting;
    36.  
     
  2. VengeanceDesign

    VengeanceDesign

    Joined:
    Sep 7, 2014
    Posts:
    84
    Does Unity's scaled down Mono C# implementation have SemaphoreSlim? I'd look into that.
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Unity uses .net 2.0 still, so it's very possible what you are trying to access is not included. Some day in the future they will support higher versions, I believe they are still in testing/development.
     
    Kiwasi likes this.
  4. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    But surely there must be a way to incorporate more recent .net classes in Unity projects?
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can google the source to most C# classes. As long as it doesn't rely on any new language features, you can drop it straight into your project.
     
  6. VengeanceDesign

    VengeanceDesign

    Joined:
    Sep 7, 2014
    Posts:
    84
    Also be very, very sure that the class doesn't depend on a newer version of some part of the .net library. It is possible that the class may see the required libraries/classes there, but the SemaphoreSlim class only works properly with updated versions of those libraries. Since you're working with semaphores, chances are a lot of tweaks and bug fixes may have been made over the years to make sure they work properly.