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

.NET Standard 2.1

Discussion in 'Experimental Scripting Previews' started by runner78, Oct 8, 2019.

  1. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    Is there a plan/ETA for the .NET Standard 2.1 support?

    Standard 2.1 no longer work with the "old" .NET 4.x Framework, and Mono support it with version 6.2.
    Would new features like Span<T> only be available if you selected NET Standard 2.1?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    We don't current have an ETA for .NET Standard 2.1 support in Unity. We will make an announcement if/when we have an idea about support.
     
  3. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    You can use backported version of Span<T> from this NuGet-package: https://www.nuget.org/packages/System.Memory/

    But standard BCL APIs that actually utilize this type are unavailable :(
     
  4. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    Some benefits with Span<T> would be the stackalloc without unsafe code. In some cases you can maybe replace native arrays.
     
  5. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    I'd love to see support for .net standard 2.1 sooner rather than later.
    So many awesome new things it adds like Span, ValueTask, ...
     
    VizworxInc and phobos2077 like this.
  6. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    Definitely would love to see support for .net standard 2.1
     
    VizworxInc likes this.
  7. mandisaw

    mandisaw

    Joined:
    Jan 4, 2018
    Posts:
    82
    Count me among the folks waiting for .NET Standard 2.1 support in Unity. But I think Microsoft is the prime mover here - according to last years' MSFT announcement blog post the new standard brings breaking changes that are mainly of interest to advanced users. I read that as implementation/upgrade will be cautious and possibly stay in Experimental/Preview mode for quite a while.

    Personally, my project timelines won't support testing out the new runtime for a while yet, so if it shows up in 2019.3 or even 2020.1, I'll still be a happy camper.
     
  8. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
  9. psap

    psap

    Joined:
    Jun 11, 2017
    Posts:
    2
    I have a library that uses .NET Standard 2.1 and now I see an error message saying I can't create a type from it in Unity.

    Backporting this library to .NET Standard 2.0 is possible but it will require quite a lot of additional changes.

    Any ETA updates since?
     
    Qbit86 likes this.
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Sorry, we don't have an ETA on this yet.
     
    psap likes this.
  11. amirmahdinassiri

    amirmahdinassiri

    Joined:
    May 22, 2020
    Posts:
    2
    As .Net Standard 2.1 was released mid-2018 as a long time support version, it's surprising that Unity has not considered supporting this version as of mid-2020! Unity aims at cross-platform game development, which collides with .Net standard goals. I would personally love to see more support for cross-platform C# backend code. Thanks, and keep up the amazing work.
     
  12. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    Slightly crazier to me is 2.1 apparently being a breaking release. Emphasis on it being a minor version. A breaking release by Microsoft. Is this some kind of sorcery?
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    We still don't have an ETA for .NET Standard 2.1 support in Unity. Unity does support .NET Standard 2.0 though.

    .NET Standard 2.1 is not just an API update, it also requires the .NET runtime support default interface methods. We don't have support for this feature in Mono or IL2CPP yet. Once that support is available, .NET Standard 2.1 support will be possible.
     
    Qbit86 likes this.
  14. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    How about telling people "It's not supported by the runtime, don't try to use it"?
     
    VizworxInc likes this.
  15. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Sorry, I'm unclear what you mean. Can you elaborate on where we should be informing users about this?
     
  16. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    The compiler throws an error if you try to use default interface implementations on a runtime that doesn't support it (like the current .NET Framework 4.7.something equivalent), thus there's no risk of issues arising from it unless there's miscommunication about the lack of runtime support.
    From my understanding, you could support C# 8 and .NET Standard 2.1 without a runtime update, telling people only "Default interface implementations from C# 8 are currently unavailable because Unity's runtime doesn't support it" in the release notes and the usual release blog post. All we need is good communication. If you want to make it extra clear, have the Visual Studio Tools for Unity analyzer issue a message with the above quote when the CS8701 error is detected.
     
    VizworxInc and JaredThirsk like this.
  17. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Thanks, I understand the question better now.

    This is exactly what we have done for C# 8 support :). You can get it in the latest 2020.2 alpha release of Unity. Although we've not put out a release blog post yet.

    I think the situation is different for .NET Standard 2.1, as it requires default interface implementation support from the runtime.
     
  18. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    I don't think so? Default interface implementations requires runtime support, but I don't think it uses any new types. There's no hard connection between the .NET Standard 2.1 class libraries and the .NET Core 3.1 runtime, is there?
     
    VizworxInc and Qbit86 like this.
  19. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Ahh yes, you are correct here. .NET Standard 2.1 is simply the reference profile, and does not say anything about how the BCL code used at runtime actually is implemented. My thoughts on this issue were muddled.

    At the moment, the best chance for us to support .NET Standard 2.1 is with an upgrade to the latest Mono BCL implementation, which does support it. That code requires default interfaces to be implemented in the runtime. We have work currently in progress to make this happen, but we don't have a release ETA yet.
     
  20. ScottKane

    ScottKane

    Joined:
    Aug 24, 2019
    Posts:
    81
    Is this for real? You're saying Unity only now has work in progress to support netstandard 2.1 with no ETA and we are stuck using technology from late 2017... at this rate .NET 5 will be released before you support netstandard 2.1, are we then going to be waiting years to get an uplift for that too?
     
    VizworxInc likes this.
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Yes, that is the current status. I'm unsure yet about a timeline for .NET 5 support, but we are working on it.
     
  22. onehundredfeet

    onehundredfeet

    Joined:
    Oct 31, 2010
    Posts:
    15
    I'm really disappointed to hear that. I've been a long time Unity user (since v1) and advocate. The gap between unity's .net and the rest of the worlds is growing. It's causing a lot of friction between Unity and the packages I want to use.

    .net standard 2.1 or net 5 would be welcome as soon as possible. I understand it may be difficult, but the .net compatibility is one of your main selling points.

    However, after the IPO, it's possible this will be even further delayed. Really disappointing.
     
  23. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    Are the packages you want to use already targeting .NET 5 or .NET Standard 2.1? My experience so far is that most packages target .NET Standard 2.0 and that is still generally recommended approach from Microsoft.

    I am not aware of any relationship between an IPO and a migration plan to a new .NET runtime/ecosystem. We will announce any details about .NET 5 as soon as we have an achievable plan for migration and dealing with the breaking changes as they affect Unity and our users.
     
    phobos2077, fherbst, NotaNaN and 2 others like this.
  24. CreepyGnome

    CreepyGnome

    Joined:
    Oct 10, 2009
    Posts:
    9
    I am curious if Unity uses Mono why is it so hard to support .NET Standard 2.1?

    Mono added support for that in Sept 2019 along with compiler support C# 8. We are over a year since it was added and you are saying that Unity still doesn't support .NET Standard 2.1?

    If Mono supports it why doesn't Unity get automatic support just by upgrading to support Mono 6.4.0 or later? Is Unity 2020 still on Mono 5?
     
    VizworxInc, phobos2077 and Qbit86 like this.
  25. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    Because they've modified Mono so much that it would take a lot of work to update their fork. Stupid decision if you ask me.

    https://github.com/Unity-Technologies/mono
     
    VizworxInc, bdovaz and Qbit86 like this.
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    We have some work in-progress and more future work planned to upgrade to the latest version of Mono, which will bring .NET standard 2.1. support. However it is not yet complete.
     
  27. Rib

    Rib

    Joined:
    Nov 7, 2013
    Posts:
    39
    Is there maybe a slim chance of getting a vague estimate of when we might see .NET Standard 2.1 support become available in Unity?
     
    phobos2077 and JaredThirsk like this.
  28. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    No, we don't have an ETA yet, sorry!
     
  29. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    Now that .NET 5 is out this is becoming more of an issue, we would like to move our shared libraries over to .NET 5 but we are limited by what Unity can use. What can we do to convince Unity to assign some more resources to this?
     
    phobos2077, NotaNaN, Ramobo and 4 others like this.
  30. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    Product Manager for the .NET area at Unity here.

    We are hearing the user feedback on aligning with the latest development in the .NET ecosystem loud and clear and it is important to us to provide the best possible C#/.NET experience in Unity. While we do not have any plans to share at the moment, we are actively working on both short and long term plans within this area.
     
    cxode, solarisn, Elringus and 12 others like this.
  31. JeromeGodboutAmotus

    JeromeGodboutAmotus

    Joined:
    Apr 24, 2020
    Posts:
    40
    I for would love to stop having macro #if and 2 different .csproj for my project, one for 2.0 version of my lib for unity and 2.1 for my desktop, Xamarin and Blazor application. It make supporting Unity more and more difficult over time. I would upvote support for this.

    I cannot slow down my other project from using 2.1 only Unity is dragging behind now a day, 2.1 has been out for a long time, maybe they wait for .Net 6???
     
  32. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    You don't need two different csproj's, you can replace single <TargetFramework> with multiple <TargetFrameworks>.
     
  33. JeromeGodboutAmotus

    JeromeGodboutAmotus

    Joined:
    Apr 24, 2020
    Posts:
    40
    TargetFramework is only fun if your API is covered by both frameworks. If the lib is fully compatible with it, yeah sure, but this is not always the case, sometime you have to prevent part of it cause it require more recent capability or dependencies this quickly get out of hands.
    I can only use a single csproj and define value there and perform the macro into the source, but this is getting messy. I made 2 csproj and include the proper project instead was more clean in the end. One for Unity and 1 for the rest (Xamarin, Blazer, Desktop, Core...).
     
  34. supermeip

    supermeip

    Joined:
    Mar 31, 2014
    Posts:
    9
    Are there any estimates here yet? The amount of time it seems people have been waiting on such a simple request seems pretty absurd to me.
     
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    No, I don't want to provide an estimate yet, sorry.

    To add some detail, this is a pretty complex task, as the current Mono class libraries that Unity ships do not support .NET Standard 2.1. So the task involves updating the Unity fork of Mono to the latest code from the upstream repository, which involves changing much more than the compile time profile.

    So although it seems simple from the outside, there are a lot of moving parts to keep straight. Our goal is to do this update to Mono without breaking any existing projects, so it does take some time.

    I wish that I could provide a better timeline now, but we're not ready to do that yet.
     
  36. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    So basically, the class library update also involves a runtime update, which hopefully means improved performance without user code changes? Not as fast as CoreCLR, definitely, but still welcome.
     
  37. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,931
    Yes, exactly.
     
    triple_why and Ramobo like this.
  38. anorak3

    anorak3

    Joined:
    Apr 10, 2018
    Posts:
    8
    Please prioritize this for a climate change project
     
    Qbit86 likes this.
  39. Ramobo

    Ramobo

    Joined:
    Dec 26, 2018
    Posts:
    212
    What? Lower power usage or something?
     
  40. anorak3

    anorak3

    Joined:
    Apr 10, 2018
    Posts:
    8
    Microsoft.EntityFrameworkCore 5
     
  41. triple_why

    triple_why

    Joined:
    Jun 9, 2018
    Posts:
    47
    I wanted to add a loosely related note here.

    I've built a .net standard 2.0 dll, which performs heavy calculations on float-type data. When I consume it from .net core 3.1 console app (for testing purposes), and Unity (with api compatibility level .net standard 2.0), I observe very slightly different numeric results. The discrepancy ratio is about 1~2/100000, so for vast majority of cases this is quite negligible.
     
  42. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    Maybe it may be because Unity's Mono currently handle floats internal as double. This will probably change with the mono update.
     
    NotaNaN and triple_why like this.
  43. SLGSimon

    SLGSimon

    Joined:
    Jul 23, 2019
    Posts:
    80
    nik_d, NotaNaN and triple_why like this.