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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Stand alone dotnet standard 2 is AOT only?

Discussion in 'Experimental Scripting Previews' started by snacktime, Jul 26, 2021.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So when did this happen? Was it ever mentioned and where? Can't find anything in the documentation mentioning this (or any current docs on .net standard 2 period actually).


    Also, why is .net a banned word lol?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    Can you elaborate? I'm unclear what you are asking about.
     
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So this might be a linux thing I guess although that would seem odd. But a stand alone linux build using the new build configuration which has a mono 2x target which I assume is standard 2, is AOT. Api's like Reflection.Emit are throwing platform not supported.


    Edit: platform not supported is I think not correct, I think the original exception was rethrown as that. It was in protobuf-net which we have an AOT version of but for a headless server I skipped using it, until it started throwing on Emit.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    What version of Unity are you using? Also, can you send a screenshot of the player settings that cause this issue?
     
  5. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    2020.3.14.1f

    upload_2021-7-26_10-31-36.png

    Player settings but I don't think these are relevant when using the build configuration.

    upload_2021-7-26_10-33-26.png
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    Thanks for the details - I believe that I understand what is happening now.

    First of all, the fact that Script Backend is displayed as Mono2x is probably a bug. The "Mono2x" is the name of the enum inside the code. The display name should be "Mono". Background - the "2x" part here means version 2 of the Mono embedding API - it is entirely unrelated to .NET Standard 2.0.

    Second, when you choose an Api Compatibility Level of ".NET Standard 2.0", any code with System.Reflection.Emit API calls will not compile in Unity script code. Since you are seeing errors at runtime, I suspect that you have some separately compiled assembly which is not built against .NET Standard 2.0 where the System.Reflection.Emit is used.

    So, I think the bottom line is that if you want to use System.Reflection.Emit APIs, please choose the .NET 4.x Api Compatibility Level. That indicates to Unity that you want a base class library implementation which has support for System.Reflection.Emit.
     
    snacktime likes this.
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Thanks a lot for clearing this up. It is a separate dll that when used with standard 1.3+ requires Reflection.Emit.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    Note that in Unity 2021.2 this behavior will change. We've "loosened" the behavior, so that any time the Mono scripting backend is used, the base class library implementation will be a full JIT implementation, regardless of the Api Compatibility Level chosen.
     
    NotaNaN, bdovaz and JesOb like this.