Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

mscorlib mismatch between unity module dependencies and loaded assembly

Discussion in 'Experimental Scripting Previews' started by pointcache, Jan 2, 2019.

  1. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    Im trying to compile some code with roslyn,
    i provide the compiler with mscorlib loaded through
    Code (CSharp):
    1. AppDomain.CurrentDomain.GetAssemblies()
    which should give me the currently loaded mscorlib.
    It gives me mscorlib 4.0, which is correct as it is set in unity player settings.
    However when building with roslyn i got
    upload_2019-1-2_20-5-19.png

    Upon looking into CoreModule, i find out it references mscorlib 2.0
    How would i set this up, so i can compile?

    The returned asmb is MonoBleedingEdge\lib\mono\unityjit i assume coremodule and friends dont use it?
     
    Last edited: Jan 2, 2019
  2. mike-voorhees

    mike-voorhees

    Unity Technologies

    Joined:
    Aug 9, 2016
    Posts:
    46
    Engine assemblies such as UnityEngine.CoreModule are compiled against the lowest supported framework assemblies, which means they are compiled against mscorlib 2.0. This allows us to use the same assembly when running with the old .NET scripting runtime (which will use mscorlib 2.0) or the new .NET scripting runtime (which will use a mscorlib 4.0).

    The key thing to keep in mind is that the mscorlib an assembly is compiled against may not be the same one that is currently being used at runtime.

    It's hard for me to give concrete advice based on the limited information provided, but a couple pointers that may help.

    * Make sure you are not passing Roslyn multiple paths to different mscorlib.dll files
    * Make sure you are passing Roslyn /nostdlib+
    * Introduce a compiler error in a script, then search the Editor log for `-----Compiler Commandline Arguments:`. The lines that follow will show the command line arguments we are passing to the compiler. You will likely want something similar.
     
    pointcache likes this.
  3. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    579
    thank you Mike, i fixed it by manually providing a path to
    Code (CSharp):
    1. @"C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll"
    for the compilation. Works well, but only with .net standard 2.

    Problem with .net 4x is that script assemblies (csharp + first pass) want to compile against mscorlib 4.0, while core needs 2.0, and i need both Unity assemblies and user scripts assemblies to compile. I haven't look deep into it yet, i think it may be possible to resolve with deeper knowledge of roslyn api, but i put it in a bag for later.

    will do