Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug bin-linux64 expected by Runtime Compiler

Discussion in 'Linux' started by kiriri, Jan 2, 2018.

  1. kiriri

    kiriri

    Joined:
    Jan 14, 2011
    Posts:
    107
    Code (CSharp):
    1. using System;
    2. using System.CodeDom.Compiler;
    3. using System.Linq;
    4. using System.Reflection;
    5. using System.Text;
    6. using Microsoft.CSharp;
    7. using UnityEngine;
    8.  
    9.     public class RuntimeCompiler : MonoBehaviour
    10.     {
    11.         public void Start()
    12.         {
    13.             Debug.Log(CreateFunction().Invoke(null,new object[]{2,3}));
    14.         }
    15.      
    16.         public static MethodInfo CreateFunction()
    17.         {
    18.             var code = @"
    19.                using UnityEngine;
    20.      
    21.                public class Test
    22.                {
    23.                    public static void Foo(int a, int b)
    24.                    {
    25.                        Debug.Log(""Hello, World!"" + a  + """" + b);
    26.                    }
    27.                }";
    28.          
    29.             var param = new CompilerParameters();
    30.  
    31.             // Add ALL of the assembly references
    32.             foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(p => !p.IsDynamic))
    33.             {
    34.                 param.ReferencedAssemblies.Add(assembly.Location);
    35.             }
    36.  
    37.             // Add specific assembly references
    38.             param.ReferencedAssemblies.Add("System.dll");
    39.  
    40.             // Generate a dll in memory
    41.             param.GenerateExecutable = false;
    42.             param.GenerateInMemory = true;
    43.  
    44.             CSharpCodeProvider provider = new CSharpCodeProvider();
    45.             CompilerResults results = provider.CompileAssemblyFromSource(param, code);
    46.  
    47.             if (results.Errors.Count > 0) {
    48.                 var msg = new StringBuilder();
    49.                 foreach (CompilerError error in results.Errors) {
    50.                     msg.AppendFormat("Error ({0}): {1}\n",
    51.                         error.ErrorNumber, error.ErrorText);
    52.                 }
    53.                 throw new Exception(msg.ToString());
    54.             }
    55.  
    56.             Debug.Log(results.CompiledAssembly);
    57.          
    58.             Type binaryFunction = results.CompiledAssembly.GetType("Test");
    59.             return binaryFunction.GetMethod("Foo");
    60.         }
    61.  
    62.     }
    63.  
    Above is a simple example of a bug, where the .net compiler is looking for mono in a folder called bin-linux64 while the correct folder would be just bin.
    It's fixed if you copy and paste
    /opt/Unity/Editor/Data/MonoBleedingEdge/bin
    and rename it to bin-linux64 .

    Ran script under .Net 4.6 .

    Cheers!

    EDIT : Might be part of the pinned MonoBleedingEdge issue. If so, then sorry for double posting.
     
    Last edited: Jan 2, 2018
  2. PJayB

    PJayB

    Unity Technologies

    Joined:
    Apr 24, 2017
    Posts:
    105
    I'm not sure it is. We'll look into this. Thanks for reporting.