Search Unity

System.Diagnostics, Debug.Log error

Discussion in 'Scripting' started by Serellyn, Jul 19, 2012.

  1. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    At the moment I'm trying to launch a .exe file from my code in Unity.
    For this code I need to import System.Diagnostics, since Process is in the Diagnostics.

    But, when I then try to use Debug.Log I'm getting an error, and as soon as I delete the import of the System.Diagnostics, Debug.Log starts working again.
    I'm getting the following error when I've Imported the System.Diagnostics and try to use Debug.Log.
    Code (csharp):
    1.  
    2. Assets/Scripts/Main.cs(24,25): error CS0104: `Debug' is an ambiguous reference between `UnityEngine.Debug' and `System.Diagnostics.Debug'
    3.  
    So what could be the problem? I'm using the following code
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Diagnostics;
    5.  
    6. public class Main : MonoBehaviour {
    7.    
    8.     private string button1;
    9.    
    10.     void Start () {
    11.         Camera.main.backgroundColor = Color.black;
    12.         button1 = "Button 1";
    13.     }
    14.    
    15.     void OnGUI() {
    16.         if(GUI.Button(new Rect(50, 50, 200, 40),button1)) {
    17.             string path = @"C:/Users/VENUS/Documents/Ernst/HEIM Project/Unity/Builds/Sonar.exe";
    18.             Process sonar = new Process();
    19.             sonar.StartInfo.FileName = "Sonar.exe";
    20.             sonar.StartInfo.Arguments = path;
    21.             sonar.Start();
    22.             Debug.Log("wut");
    23.         }
    24.     }
    25. }
    26.  
    27.  
     
    Last edited: Jul 19, 2012
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    It's exactly what the error message says. You are using the keyword Debug and the compiler can't determine which Debug you mean.

    You can refer to things by their fully qualified name (i.e. UnityEngine.Debug, System.Diagnostics.Process).
     
    TheSwamp and chriswagie like this.
  3. Serellyn

    Serellyn

    Joined:
    Sep 30, 2011
    Posts:
    104
    Thank you for clarifying that for me. And it makes sense, but I don't like it :p
     
  4. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Another way to work around this - if you only need to use one of the Debug classes directly - is to define an alias like so:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Diagnostics;
    4.  
    5. using Debug = UnityEngine.Debug;
    6. //...
     
    synthc, tapia641, Bunny83 and 19 others like this.
  5. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    How do you do that in unityscript?
     
  6. zekecrall

    zekecrall

    Joined:
    Apr 23, 2020
    Posts:
    2
    thanks you just save my small bran
     
    obtenid and SGmakerPRO like this.
  7. aallawati86

    aallawati86

    Joined:
    Apr 10, 2020
    Posts:
    1
    I have same problem and this still not resolved.
    When entre Debu.Log same error happened. Please provide your support.
     
  8. Arieless91

    Arieless91

    Joined:
    Apr 25, 2020
    Posts:
    1
    I resolve it deleting "using System.Diagnostics;"
     
  9. elijahvalongo

    elijahvalongo

    Joined:
    May 17, 2020
    Posts:
    1
    thank you ,man that really worked
     
    taravatanvari9608 likes this.
  10. bahriken

    bahriken

    Joined:
    Jun 14, 2020
    Posts:
    1
     
  11. protiuxdesignlabs

    protiuxdesignlabs

    Joined:
    Oct 15, 2020
    Posts:
    1
    I've deleted the using System.Diagnostics; line and the compile runs fine. But if I go back and work in the script more, the System.Diagnotstics gets automatically replaced. Have I made a selection in the creation of my project that causes this to be inserted?
     
  12. TheGBeast

    TheGBeast

    Joined:
    May 15, 2020
    Posts:
    1
    Hey do you remember if you ever fixed this?
     
  13. chris73it

    chris73it

    Joined:
    Oct 15, 2013
    Posts:
    21
    Yeah, this is pretty annoying: I am using VS 2022 and Unity 2022.1.20f1
    Even though I delete the diagnostic using line, it keeps coming back: is there any way to let VS know I don't want that (other than defining a alias)?