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

System.Threading.Tasks

Discussion in 'Experimental Scripting Previews' started by BDS_Entertainment, Feb 5, 2017.

  1. BDS_Entertainment

    BDS_Entertainment

    Joined:
    Oct 26, 2015
    Posts:
    4
    Hello,

    I am trying to test Parallel.For and Parallel.ForEach in the latest experimental build, but I can't seem to reference System.Threading.Tasks.

    I also tried just dragging the .dll file from the mono bleeding edge 4.5 folder manually into my project, but while I was able to reference the namespace, a Parallel class did not exist. Am I forgetting something?
     
    rakkarage likes this.
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Check API Compatibility Level. Maybe, you've run into the same problem as I did.
     
  3. BDS_Entertainment

    BDS_Entertainment

    Joined:
    Oct 26, 2015
    Posts:
    4
    I think I might have the same problem you are running into, however, when I checked the editor log it reports the correct sdk version of 4.6. I do get some message in the console I can't quite decipher which has something to do with an SDK version sometimes when I open up the project, but I am unsure if that message has anything to do with this.

    By the way, I also couldn't use "MethodImplOptions.AggressiveInlining" either, as "AggressiveInlining" was not a defined option.

    I'm not sure if this information is useful (regarding my troubles referencing System.Threading.Tasks), but initially I had the same problem trying to reference System.Numerics, but dragging the .dll from the mono bleeding edge 4.5 folder into my Assets folder worked for this particular case.
     
  4. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Not sure about Numerics, but everything else just works. For example:
    Code (CSharp):
    1.     [MethodImpl(MethodImplOptions.AggressiveInlining)]
    2.     private void Test()
    3.     {
    4.         Task.Factory.StartNew(() =>
    5.                               {
    6.                                   var ints = Enumerable.Range(0, 100);
    7.                                   Parallel.ForEach(ints, i => Debug.Log(i));
    8.                               });
    9.     }
     
  5. BDS_Entertainment

    BDS_Entertainment

    Joined:
    Oct 26, 2015
    Posts:
    4
    It's unfortunate, but no matter what I can't seem to get it to work. I'm unable to reference anything from System.Threading.Tasks and when I check the definition in the meta data for MethodImplOptions, AggressiveInlining doesn't even exist.

    I am glad that it works for you though, that means eventually (hopefully) I'll be able to figure it out here.

    EDIT: So I've temporarily worked around this by taking the mscorlib.dll from the bleeding edge mono 4.5 folder and replacing the mscorlib.dll in the following path:

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Unity Subset v3.5

    Everything now works and I am able to properly reference and use the TPL. Problem is, I have literally no idea what I've broken in the process by doing this. Oddly enough, everything seems to be working fine and dandy as far as the (admittedly limited amount of) Unity API and .NET 4.0+ API I've been testing. It works in both editor play mode and the built executable.

    Why did this work?
     
    Last edited: Feb 6, 2017
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @rhhzero

    Something is very wrong here. This should not be necessary, and Unity shouldn't have anything to do with the .NET framework location on your machine. Do you happen to have any MONO_* environment variables set? If MONO_PATH is set that might cause a problem like this.
     
  7. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I don't even have such a folder: \Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Unity Subset v3.5

    I have \Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5, but there's no Profile subfolder inside.

    The folder's name ― Unity Subset v3.5 ― sounds familiar. I suspect it is created by Visual Studio Tools for Unity, and I probably don't have this folder because I spent at least half an hour trying to completely uninstall VSTU and get rid of all of its traces in Program Files and the registry after installing the Runtime Upgrade Preview build.
     
  8. BDS_Entertainment

    BDS_Entertainment

    Joined:
    Oct 26, 2015
    Posts:
    4
    MAN. Thanks for the tip buddy! I also spent a stupid amount of time to do a religious wipe of Visual Studio and Unity from my machine, and I still had this problem (without using my hacky, broken, workaround). I saw that this file path was continuously referenced.

    I removed Visual Studio Tools for Unity (the one that the Unity installer keeps automatically installing even though its not even supported in this build), and everything works right off the gate. Finally! Without a doubt, my problem was VSTU which somehow was causing all my Unity projects from the experimental build to reference the framework version the default Unity versions use.
     
    Last edited: Feb 6, 2017
  9. Yossarian123

    Yossarian123

    Joined:
    Nov 6, 2016
    Posts:
    2
    I guess I can't use Parallel.For or any other System.Threading.Tasks function in the asset I was working on since it won't work by default for anyone who buys my asset. That sucks.
     
  10. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
    You need the most recent versions of VSTU in order for project generation to work correctly with the scripting upgrade preview.
     
  11. UDN_b371e0c2-57b9-4491-abd4-3aef0e02ba5f

    UDN_b371e0c2-57b9-4491-abd4-3aef0e02ba5f

    Joined:
    Jan 19, 2017
    Posts:
    1
    Go to Build Settings and Change the .Net version to (Experimental)4.6