Search Unity

Feedback [BUG?] AsyncOperationBase<T>.Task - invalid cast

Discussion in 'Addressables' started by phobos2077, Apr 26, 2020.

  1. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Situation:
    - I have an AsyncOperationHandle<IList<Object>>.
    - I wanted to expose it as public property to await and track progress, but w/o having access to the results. So naturally I just exposed it as AsyncOperationHandle (non-generic version).
    - Calling code gets this object and accesses Task property.
    - AsyncOperationHandle.Task calls AsyncOperationBase<T>.Task, but here's an issue:

    Code (CSharp):
    1.         System.Threading.Tasks.Task<object> IAsyncOperation.Task
    2.         {
    3.             get
    4.             {
    5.                 return Task as System.Threading.Tasks.Task<object>;
    6.             }
    7.         }
    Task is
    System.Threading.Tasks.Task<TObject>
    and this cast is incorrect, it won't down-cast generic class with another generic class with base class argument. It'll just always return null, resulting in an NullReferenceException.
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    phobos2077 likes this.
  3. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Create case 1243070.
     
  4. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Today I've stumbled upon this bug again, now in a different context. If you try awaiting the result of
    DownloadDependenciesAsync
    , you get this error.

    Here's a super easy reproduction step:

    Code (CSharp):
    1. await Addressables.DownloadDependenciesAsync("asset").Task;
    This will result in NRE in all cases. Because
    DownloadDependenciesAsync
    returns non-generic AsyncOperationHandle, but internal operation has generic Task instance. As a result, Task is always null when using this function.

    PS: if anyone wondering, the ticket I've created in April still hanging there. First they asked me for a "reproduction" project even though the bug is clear and no reproduction is needed. Then they've closed my case altogether. I've sent more replies of course so the ticket gets re-opened, but still no response. If only they could reduce the amount bureaucracy in QA department and just accept bugs that are already reproduced, identified in the code and explained...