Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Invalid IL code

Discussion in 'Addressables' started by xKosta, Jul 10, 2019.

  1. xKosta

    xKosta

    Joined:
    Oct 15, 2014
    Posts:
    24
    Hey, I encounter following issue during my work with Addressables.

    Code (CSharp):
    1. InvalidProgramException: Invalid IL code in [...]/<NothingAsync>d__12:MoveNext (): IL_001c: call      0x0a000315
    2. System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) (at <7d97106330684add86d080ecf65bfe69>:0)
    3. [...].NothingAsync () (at <e7100c1aed3a4fd79d4d8d0cb33b90bc>:0)
    4. [...]+<[...]r>d__7.MoveNext () (at [...]:49)
    5. --- End of stack trace from previous location where exception was thrown ---
    6. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <7d97106330684add86d080ecf65bfe69>:0)
    7. System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <7d97106330684add86d080ecf65bfe69>:0)
    8. System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <7d97106330684add86d080ecf65bfe69>:0)
    9. System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <7d97106330684add86d080ecf65bfe69>:0)
    10. System.Runtime.CompilerServices.TaskAwaiter.GetResult () (at <7d97106330684add86d080ecf65bfe69>:0)
    I am using async and await to instantiate the assets. With version 0.8.6 it worked well until I added many assets and groups. Then this error occured and I tried to fix with an update to 1.1.4.
    I still have no clue how to fix it or what causes it, this is how my code looks like and also with an interesting workaround, maybe this gives a clue what is wrong. See the attached image.

    I know that Addressables is not production ready, so this just my experience and maybe someone can use for something.
     

    Attached Files:

  2. austriahaniel

    austriahaniel

    Joined:
    May 3, 2019
    Posts:
    5
    Have you tried with..

    Code (CSharp):
    1. var gameObj = await Addressables.InstantiateAsync("key").Task;
     
  3. xKosta

    xKosta

    Joined:
    Oct 15, 2014
    Posts:
    24
    Yes, I did, but with no luck. As soon as I write the "Addressables.InstantiateAsync" Line and go to playmode, the above described error occures. It is also not possible to debug this.
     
  4. xKosta

    xKosta

    Joined:
    Oct 15, 2014
    Posts:
    24
    I have to take the last reply back, either it works with Task at the end or it is the new Unity 2019.1.10 version or both, now it works and I am very surprised.
     
    unity_bill likes this.
  5. LCLx

    LCLx

    Joined:
    Jul 5, 2019
    Posts:
    1
    I found that where is something wrong with System.Runtime.CompilerServices.Unsafe.dll which is provided by com.unity.collection. I place a newer version of that dll and the problem solved. But every time I open unity, the appliction would change that automatically. So I have to replace that every time I use that. This is definitly a bug, hope unity will update their plugin soon.
     
  6. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    69
    I've just run into this problem. But it's quite a relief that I've done nothing wrong. Hope this issue should be fixed soon.
     
  7. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    422
    Have any of you filled a bug with a repro project?
     
  8. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    92
    In my case, I've grpc in my plugins folder and it depends on a different version of the Unsafe.dll.
    I moved unity.collections from packagecache into packages and deleted collections' Unsafe.dll.
    Unity uses the version alongside grpc in my plugins folder.
     
  9. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    235
    I had exactly the same error. To be exact, I think there are 2 different issues here:

    • AsyncOperationHandle can be awaited w/o compile error, but it will produce runtime error (so it's easy to forget to access Task property and await the handle instead).
    • If I write
      await Addressables.LoadSceneAsync(addr).Task;
      I get the same error, but if I change this to:
      Code (CSharp):
      1. var task = Addressables.LoadSceneAsync(addr).Task;
      2. await task;
      the error goes away.
     
unityunity