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

Mono Upgrade Future plans for the Mono runtime upgrade

Discussion in 'Experimental Scripting Previews' started by JoshPeterson, Apr 3, 2017.

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Qbit86

    Thanks for reporting this issue. Can you submit a bug report so that we can follow-up with you when it is corrected?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    I think that is should work without any additional configuration from your side. I'll ask our QA team to look at this as well and see if we can determine the steps necessary to reproduce it. If possible can you start over with a new Unity project after VSTU 3.1 is installed? I'm interested to know if it happens in that case as well.
     
  3. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    I have filed an issue #901443 on this.

    Is there any quick workaround how to suppress referencing `nunit.framework.dll`, which redefines `System.Lazy<T>`?
     
  4. ThainaYu

    ThainaYu

    Joined:
    Nov 4, 2016
    Posts:
    18
    Will the CoRoutine would be switched to async/await?
     
  5. Astarorr

    Astarorr

    Joined:
    Jan 17, 2013
    Posts:
    41
    What exact version of .Net is supported: .Net 4.6, 4.6.1 or 4.6.2?
    In case of 4.6.2 support, i think it should be possible to use C#7 in VS2017, compile dll and use it in Unity 2017.1?

    EDIT: Just checked, it's working fine. Compiled DLL using C#7 features working fine in editor.
     
    Last edited: Apr 15, 2017
    yoyobbi and Qbit86 like this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @ThainaYu

    Initially that will not be the case. It might happen in the future, although I doubt that coroutines will be replaced entirely, as lots of existing code depends on them.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Astarorr

    We're shipping the same profile that exists in Mono version 4.8, which is pretty much .NET 4.6 and C# 6.0 support. As long as there are no new runtime features used in the C# 7 assembly, it should be fine. Note that the C# compiler which ships with Unity does not support C#7 yet though.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Qbit86

    Thanks for submitting the bug report. I'm not sure if it is possible to suppress the nunit.framework.dll reference. I'm checking on that and I'll let you know what I find out.
     
  9. MHDante

    MHDante

    Joined:
    Aug 20, 2013
    Posts:
    11
    Qbit86 likes this.
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  11. cureos

    cureos

    Joined:
    Apr 19, 2016
    Posts:
    9
    I guess we are talking about different things, which maybe add to the confusion. I am trying to create a class library in Visual Studio that I intend to consume in a Unity project.

    In the Unity 2017.1 editor, I can set the scripting runtime version to 4.6:

    unity-editor.png

    In Visual Studio 2015, with VS Tools for Unity 3.1 installed, I can however only create a class library using any of the Unity .NET 3.5 based frameworks:

    visual-studio.png

    This is still true even if I create a new C# project in VS and/or opening the Unity project as a C# project from the Unity editor.

    Instead of setting the Target Framework of my class library e.g. to "Unity 3.5 .net full Base Class Libraries", will it work "flawlessly" with the experimental Unity engine if I set it e.g. to ".NET Framework 4.6"?
     
    Last edited: Apr 18, 2017
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    I don't see the screen shots you added to your post. Can you try to add them again?
     
  13. cureos

    cureos

    Joined:
    Apr 19, 2016
    Posts:
    9
    Sorry, still a forum novice :) Now they should be visible, I hope.
     
  14. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    No worries!

    Yes! Well, there could be bugs, but Unity should support the .NET 4.6 profile with the experimental option set. So let us know about anything you build with .NET 4.6 that does not work. We will correct it!
     
    cureos likes this.
  15. cureos

    cureos

    Joined:
    Apr 19, 2016
    Posts:
    9
    @JoshPeterson OK, thanks! I will try it out and let you know how it goes. Eventually, will you ship something like "Unity 4.6 .net full Base Class Libraries" for Visual Studio?
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    I'm not sure yet. Ideally, Unity will work with the full .NET 4.6 profile, so that won't be necessary. We will likely ship a smaller profile as well (probably based on .Net Standard 2.0), but that profile is not available yet in 2017.1.
     
    cureos likes this.
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Qbit86

    Unfortunately no, there is not a way to remove the nunit.framework.dll reference. I've just learned that we are working now on making this optional, but it is not available in 2017.1b1 (although it might make a later beta). Also, we've tracked down the cause of the issue with the current nunit.framework.dll assembly. We're planning to correct it as well for a later beta.
     
  18. cureos

    cureos

    Joined:
    Apr 19, 2016
    Posts:
    9
    Where is the best place to report problems concerning this? I have one Mono 4.5 class library which references two Portable Class Libraries (profile 111, .NET Framework 4.5, Windows 8+, Windows Phone 8.1, Xamarin), and I get this error when trying to run a behavior script consuming these libraries:

    TypeLoadException: Error Loading class
    System.RuntimeType.GetMethodsByName (System.String name, System.Reflection.BindingFlags bindingAttr, System.Boolean ignoreCase, System.RuntimeType reflectedType) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/ReferenceSources/RuntimeType.cs:481)
    System.RuntimeType.GetMethodCandidates (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConv, System.Type[] types, System.Boolean allowPrefixLookup) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/rttype.cs:2825)
    System.RuntimeType.GetMethods (System.Reflection.BindingFlags bindingAttr) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/rttype.cs:3078)
    UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (UnityEditor.Build.BuildPipelineInterfaces+BuildCallbacks findFlags) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:182)​
     
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    The best option is to discuss it on the forums (maybe via a new thread in this forum section), or submit a bug report via the Unity editor.

    In this specific case, I'm unsure about what the cause is. Your situation sounds sufficiently complex enough to warrant a bug report though. Can you submit a bug with this project? If so, please do that and let me know the bug number. Thanks!
     
  20. cureos

    cureos

    Joined:
    Apr 19, 2016
    Posts:
    9
    @JoshPeterson Thanks again. I have filed a bug report, it has ID 902662.
     
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @cureos

    Thanks, we will investigate this.
     
  22. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Regarding this issue with System.Lazy and nunit.framework.dll - we have corrected it, and the fix will be available in the 2017.1.0b2 release of Unity. That release it not public yet, but when it is, please try this again.

    The problem was that NUnit implemented System.Lazy as a public class for its .NET 3.5 build. Unity ships with its .NET 3.5 build, so the conflict happened. We worked around this with a change to make the class internal in NUnit:
    https://github.com/nunit/nunit/pull/2109.
     
    Qbit86 likes this.
  23. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Thanks! I'd rather even placed it to another namespace. There is no point in mimicing existence of class from higher version of Framework in lower version. If you redefine it as `SomeInternalPseudoSystem.Lazy<T>` it will still be unbroken when compiling for higher Framework, since there still will not be any name clashes between “true” `System.Lazy<T>` and reimplemented “back-port” `SomeInternalPseudoSystem.Lazy<T>`.
     
  24. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I completely agree! This was the fastest way to get a fix for this issue. Longer term, Unity will do two different things related to this problem:

    1. Unity will ship a .NET 4.5 build of nunit.framework.dll, and use that when the new runtime and profile are targeted.
    2. Unity will provide a way to not reference nunit.framework.dll if you don't want to use it.
     
    Laicasaane, Vanamerax and Qbit86 like this.
  25. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
    I know you guys have talked about this on another thread, but I can't wait for an upgraded garbage collector, lol. (it's going to come after the .net upgrade right?)
     
  26. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
  27. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    I think we could just upbringing StartCoroutine into await pattern. Wherever it's yield return then it could became await
     
  28. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    @JoshPeterson Also, since we have taste 2017 beta for such time. Did we could ensure that unity 2017 actual release be supported .net 4.6?

    If so I could start writing my code in C#6 in beta while waiting for 2017 release
     
  29. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Alverik

    Yes, we're planing on an upgraded garbage collector after the runtime upgrade. We need to make changes to the Unity engine code that is outside of the Mono runtime as well in order to allow a generational GC to work properly. That effort is underway.
     
    AdmiralThrawn likes this.
  30. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @MrG

    I was unaware of this bug report. I'll respond directly to you via it.
     
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Thaina

    Well, it is difficult to ensure anything. When we're talking about software, things are always subject to change. :)

    However, our plan is to provide .NET 4.6 and C# 6 support with the new Mono runtime as an experimental feature in the 2017.1 release, as it is in the beta. This means it will not be officially supported in 2017.1. With that said, our goal is to move as quickly as possible to official support, so we will be corrected bugs and addressing problems with the new Mono runtime as the top priority for our team.

    In a future Unity release it will be officially supported, and hopefully soon.
     
    johanneskopf and Thaina like this.
  32. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    @JoshPeterson

    So with the annoncement of .Net Standard 2.0 preview for .net core at Build, it looks like the standard is pretty close to being finalized. Are the plans still limited to .net 4.6 + C#6 for the Unity 2017.1 release or is an upgrade already being worked on? Quite curious to see when we can be using bleeding edge C# 7 in our development workflow :)
     
  33. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @wasstraat65

    Unity 2017.1 will still include only the full .NET 4.6 profile and C# 6. We're passed the internal feature cut-off for the 2017.1 release. We are working on more profile support for 2017.2 though. I can't say for sure that it will be ready, but we're hoping to be there. At the moment, we looking to support at least the .NET 4.6 API surface and the smaller .NET Standard 2.0 API surface. We'll also likely have AOT-friendly implementations of one or both of these profiles.

    We're not sure when C# 7 will be ready yet. That comes with Roslyn compiler support, which requires some internal tooling changes to support portable PDB files in all of our tools.
     
    ThainaYu, Vanamerax and Alverik like this.
  34. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    What would an AOT-friendly implementation entail?

    I code that won't work on AOT platforms would not compile rather than crash consoles, that would be a major upgrade!
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Baste

    There are a few places in the class libraries where code simple won't work in AOT situations. It often depends on generic virtual methods or reflection that doesn't work well without a JIT. I'm not sure about all of the details yet, but an AOT-friendly implementation is a necessary feature for making the .NET 4.6 profile fully supported in Unity.
     
    Alverik likes this.
  36. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Thanks for the in-depth explanation, love this openness about the progress!

    If I understand correctly, C#7 is currently not supported by the latest official Mono runtime/compiler yet? Is the plan to wait until Mono implements support for it? You mention Roslyn, does that mean you will switch to the Roslyn compiler as a next step instead of waiting for the mono compiler support?
     
  37. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Mono 4.8 does not support C# 7, but Mono 5.0 has switched to Roslyn by default and does support C# 7. Internally, we are working to update Unity to use Mono 5.0, so we could ship C# 7 support using Roslyn in a future release of Unity. For the moment, our internal build with Mono 5.0 is switched to use the mcs compiler instead of Roslyn, as we need to update the tools in the Unity ecosystem to work with Roslyn as well.

    So we are planning to ship Unity with C#7 support and Roslyn, but I'm not sure when yet. This is all really early internally (as in just started working completely yesterday).
     
  38. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Thanks for the detailed clarification again! Love it that you guys are working on this :)
     
  39. ThainaYu

    ThainaYu

    Joined:
    Nov 4, 2016
    Posts:
    18
    For now I just hope that C#6 would be sure tobe a next non-beta release
     
  40. Mr-KoSiarz

    Mr-KoSiarz

    Joined:
    Apr 22, 2017
    Posts:
    4
    @JoshPeterson
    Can I have installed Unity beta version side by side with stable?
     
  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Mr-KoSiarz

    Yes, you can have multiple Unity versions installed. Make sure you install the beta version to a different directory. That's all you need to do.
     
  42. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    I usually rename the ProgramFilesFolder property in the installer to Unity5.X.XfX or Unity5.X.XpX or whatever it is the installer title says about the version.
     
  43. salmelo

    salmelo

    Joined:
    Nov 25, 2014
    Posts:
    4
    Please don't remove coroutines. They're very useful for temporary jobs that need to operate in sync with the frame rate without having to spawn an entire behaviour with an update function. (I often use them for controlling visual movement in a turn based game, for example.)
     
  44. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    @salmelo Task and async/await is a standardized way C# do the coroutine. It actually the same concept but better. Just unity don't update C# version too long so we can't use that great feature of C# 5
     
  45. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    Indeed. It would be better to just use Tasks and async/await. You can share existing code for a problem with non-Unity applications/libs without going to the trouble of porting it as close as possible for Unity(if that's possible at all). It's more cohesive/consistent that way.

    Also like Thaina mentioned, they are standardized, which means they are more robust and by now a more powerful tool,considering the variety of frameworks that use it.
     
  46. salmelo

    salmelo

    Joined:
    Nov 25, 2014
    Posts:
    4
    Task and async/await are not the same thing as coroutines tho. Task is for asynchronous operations, something currently very difficult to achieve in Unity without Task and async/await. Coroutines are a way of running code in lock-step with the frame rate, the same way that you would in a behaviours Update() method. While they can be used as a sort of psuedo asynchronous operation, that's not what they're actually for (imo) and the fact that there now exists a better way to do asynchronous operations is no reason to get rid of them. That's like saying "now that we have an amazing new screwdriver, we can get rid of hammers entirely."

    As an example; I often use them for components who need to do something, such as move to a specific point, but won't be doing it all of the time. The component will have a public function to tell it that it needs to go to a new location wherein it will start a coroutine to handle the frame-by-frame movement. When it gets there the coroutine ends. Without coroutines you'd have to handle the movement in Update or LateUpdate, which would work, but now every moving piece is having Update called every frame, even when 90% of the time it won't be doing anything. I realize superfluous updates aren't the greatest performance hit without very large numbers, but even so I'd rather avoid them. I also like to compartmentalize the motion into a single function.

    I'm sure there's a way you could achieve that behavior with async/await but frankly that would be a bit overkill. I don't need multithreading to do the job of a coroutine. And that's my real point: I'm very excited to be getting a new screwdriver, but I still like my hammer too.
     
    AdmiralThrawn likes this.
  47. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    Tasks are not multithreading. they can be scheduled in another thread, but they are just a better syntax to do the same thing a Coroutine does.

    i.e. one could do "await new WaitForSeconds(x)" in an async method instead of "yield return new WaitForSeconds(x)" in a coroutine, and Unity could make the two statements behave exactly the same (they need to have the yield instructions implement the "Awaiter pattern" for them to be awaitable)

    what Tasks can do better than Coroutines are:
    1) returning values: "var result = await InnerTask()" - with coroutines, you have to either pass a lambda or use a field
    2) handling exceptions:
    - if a Task throws an exception, it gets catched and retrown when you await - then you can handle it
    - if a Coroutine throws an exception, Unity and prints it, but there is no propagation - any other coroutine that is waiting for it is never resumed
    - you can put a try-catch block around an await, but not around a yield (you can yield in a try-finally, but Unity doesn't call the finally block if it gets interrupted someway - e.g. StopCoroutine)
     
    AdmiralThrawn, alexzzzz and npatch like this.
  48. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    247
    @salmelo The lockstep part isn't something Coroutines can do inherently. It's just something that Unity devs created on top of the base for you to use in tandem with the rest of Unity's code.Doesn't mean they won't provide the same with Tasks and async/await.

    @JoshPeterson can enlighten us more on this issue.
     
  49. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Sorry if I derailed the discussion a bit earlier. I'll be very clear:

    There are no plans to remove coroutines from Unity any time soon.

    We're in the early stages of having support for async/await style programming in Unity. We're excited to see where this paradigm can take us, but we're not throwing out anything old. Theoretically it might be possible for async/await to replace coroutines, as they are similar. But as others have mentioned here, coroutines in Unity are tightly coupled to the frame update mechanism, and so are rather useful.

    In addition, supporting both coroutines and async/await doesn't add significant runtime or develop overhead for us, so we're planning to keep both.

    Since async/await is new to Unity, I would encourage people to experiment with it. We'd love to get feedback about which patterns and practices are useful. As with any new feature, please use caution and profile your code with it. There is a good bit of code generated by the C# compiler for async/await that might have an impact on performance (both via additional allocations and extra code execution).
     
    codestage, johanneskopf and npatch like this.
  50. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    We don't pretend that tomorrow Unity removes Coroutines.

    But I think that Unity should encourage and teach people on using async/await instead so we can make a better transition supported by Unity.

    Also many developers like me want to be able to reuse class libraries outside of Unity that aren't tied to Unity API.

    That's why on other threads I asked if Unity would replace part of it's API with System.Numerics namespace.