Search Unity

ArgumentNullException appear randomly in Unitywebrequest

Discussion in 'Scripting' started by MBlomme, Jul 21, 2018.

  1. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    9
    Hi everyone,

    I'm posting here today because I have some weird issues using UnityWebRequests

    I'm developing an app that requires getting some files over the Internet. In order to get those files I use UnityWebRequests and a FileStream to download everything locally, but sometimes I have issues with some files that stop being downloaded (while some others are being downloaded entirely), when I look with my debugger, I discover that many fields in my UnityWebRequest have the same exception :

    Code (CSharp):
    1. System.ArgumentNullException : Value cannot be null.
    2. Parameter name: _unity_self


    Does anyone know where that could come from?

    Thanks a lot
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,585
    You could try and simplify the problem. Create a new scene and add into it only the download script (give some hardcoded filenames etc. just to make it run). Can you reproduce the problem that way?

    If not, then maybe something else in the real scene is causing the problem. If it is repeatable, then try posting that cut-down code here. It may help others to see what is happening.
     
  3. GGeff

    GGeff

    Joined:
    Nov 11, 2014
    Posts:
    40
    Did you find a solution to this? I'm having it as well.
     
  4. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    9
    I didn't find a solution so I went with another way to download my files (using WebClient and async methods)
     
  5. Rodolphito

    Rodolphito

    Joined:
    Jan 31, 2014
    Posts:
    16
    I've been getting this too, in 2018.2 and also in 2018.3.0b5, its a real bummer. I was hoping the new web requests would be nice and robust... does anyone know of a work-around? My old code used WWW, but since that was obsoleted I switched to UnityWebRequest, is WebClient fast and full cross platform?
     
  6. tonyhan

    tonyhan

    Joined:
    Dec 29, 2015
    Posts:
    6
    me too!
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    It looks like you are using UnityWebRequest or Download/UploadHandler after it has been disposed of. If you put UnityWebRequest inside using() block or explicitly call Dispose(), it cannot be used afterwards.
     
  8. Rodolphito

    Rodolphito

    Joined:
    Jan 31, 2014
    Posts:
    16
    Thanks for the response, I solved the problem by having less concurrent downloads. I was downloading ~100 small files simultaneously, and it seems that it did not like doing that. Maybe it has to do with available system resources prohibiting having too many files open being written to simultaneously, and not unity code?
     
  9. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    7
    Having exactly the same problem, periodically doing UnityWebRequest, after a while it fails with timeout and the game has to be restarted as making any new requests causes:
    Code (CSharp):
    1. System.ArgumentNullException : Value cannot be null.
    2. Parameter name: _unity_self
    Happening on Unity 2019.1.9f
     
  10. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    2,226
    All symptoms of reusing UnityWebRequest after it has been disposed. It's a bug in your code.
    If you call Dispose() method on UWR or put UWR object in a using block (which calls Dispose() uppon leaving the block), you have to make sure you don't use that same UWR object. You should create a new one.
     
  11. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    7
    Thanks, yes, that was the cause.