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

Resolved Mono.exe can not be found in stand-alone.

Discussion in 'Editor & General Support' started by pawelekezg, Oct 8, 2021.

  1. pawelekezg

    pawelekezg

    Joined:
    Nov 7, 2019
    Posts:
    12
    Hello,
    I am making a game in which a player can type his own script and play it runtime. It works perfectly fine in Unity Editor but when i try building the game and run the script i get an error which i can't solve. I hope you guys can help me.
    My project is set:
    Scripting Backend: Mono
    Api: .NET 4.x
    Code (CSharp):
    1.  
    2.  
    3. public void PlayScript()
    4.     {
    5.         if (compilationWindow.activeSelf == true)
    6.             return;
    7.  
    8.         StringBuilder source = new StringBuilder();
    9.         source.Append("using UnityEngine;\nusing SplitAndMerge;\npublic class PlayersCode{\npublic static void Run(){\nSplitAndMerge.Program.MainUnity(new string []{\"\n");
    10.  
    11.         source.Append(scriptText.text.Replace("\u0022", "\u005c\u0022"));
    12.         source.Append("\"});}}");
    13.  
    14.         var assembly = Kompiluj(source.ToString().Replace("\n", ""));
    15.         var method = assembly.GetType("PlayersCode").GetMethod("Run");
    16.         var del = (Action)Delegate.CreateDelegate(typeof(Action), method);
    17.         del.Invoke();
    18.         showCompilationError();
    19.  
    20.  
    21.     }
    22. ........
    23.  private Assembly Kompiluj(string kod)
    24.     {
    25.         var provider = new CSharpCodeProvider();
    26.         var param = new CompilerParameters()
    27.         {
    28.             GenerateExecutable = false,
    29.             GenerateInMemory = true
    30.         };
    31.         //standardowe assembly z projektu itp
    32.         foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
    33.         {
    34.             param.ReferencedAssemblies.Add(assembly.Location);
    35.         }
    36.         //dodatkowe assembly
    37.         param.ReferencedAssemblies.Add("System.dll");
    38.         param.ReferencedAssemblies.Add("Assets/Resources/cscs.dll");
    39.  
    40.  
    41.  
    42.         var results = provider.CompileAssemblyFromSource(param, kod);
    43.  
    44.         Debug.Log(results.Errors.Count);
    45.         if (results.Errors.Count > 0)
    46.         {
    47.             foreach (CompilerError CompErr in results.Errors)
    48.             {
    49.                 Debug.Log(
    50.                      "Line number " + CompErr.Line +
    51.                      ", Error Number: " + CompErr.ErrorNumber +
    52.                      ", '" + CompErr.ErrorText + ";" +
    53.                      Environment.NewLine + Environment.NewLine);
    54.             }
    55.         }
    56.         return results.CompiledAssembly;
    57.  
    58.     }
    59.    
    60.  
    I tried creating the folder there and i copy pasted files from unity, it "worked" but i still got another error :
    Exception: Compiler failed to produce the assembly. Output: ''
    at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch
     

    Attached Files:

    Last edited: Oct 8, 2021
  2. pawelekezg

    pawelekezg

    Joined:
    Nov 7, 2019
    Posts:
    12
    Used roslyn instead and it works ;)