Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

An attempt to obtain www.responseHeaders cauzes exception

Discussion in 'Editor & General Support' started by sergey-samus, Sep 8, 2017.

  1. sergey-samus

    sergey-samus

    Joined:
    Jun 6, 2016
    Posts:
    1
    Hi all.
    I recently updated my project to unity 2017.1.0p5 and meat strange behaviour.
    When i load local file using WWW class and then try to check responseHeaders property of WWW class instance. It throws exception:

    ERROR:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.WWW.get_responseHeaders () (at C:/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:158)
    3. TestLocalLoading+<LoadLocalFile>c__Iterator0.MoveNext () (at Assets/Scripts/TestLocalLoading.cs:20)
    4. UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    SAMPLE CODE:
    Code (CSharp):
    1. public class TestLocalLoading : MonoBehaviour
    2. {
    3.     public void TesLoacalLoading()
    4.     {
    5.         StartCoroutine(LoadLocalFile());
    6.     }
    7.  
    8.     private static IEnumerator LoadLocalFile()
    9.     {
    10.         var filePath = "file://" + Application.dataPath + "/TestLocalLoading.txt";
    11.         var www = new WWW(filePath);
    12.  
    13.         while (!www.isDone)
    14.             yield return www;
    15.  
    16.         Debug.LogFormat("www.text: {0}", www.text); // file loaded correctly
    17.         Debug.LogFormat("www.responseHeaders: {0}", www.responseHeaders); // this line produce exception
    18.     }
    19. }
    It's just a simple code to reproduce error.
    In Unity 5.3.4p1 all was fine. But since WWW became a wrapper for UnityWebRequest I start getting errors.
     
    Last edited: Sep 13, 2017
  2. sguyge

    sguyge

    Joined:
    Nov 15, 2016
    Posts:
    5
    I'm having the exact same problem with Unity 2017.1.1p3, the previous version 5.4.1p1 that I used doesn't have this problem. I believe this is a bug in the responseHeaders getter. @sergey-samus since you've already have a simple repro, could you please report a bug so that the Unity team can get it fixed?
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    The fix for this bug is on the way (but it will take a while for it go through backporting & release pipeline).
    The issue is that since 2017.1 WWW.responseHeaders can return null when there are no headers. This will be fixed soon to return empty dictionary.
     
  4. hexaust_

    hexaust_

    Joined:
    Mar 7, 2015
    Posts:
    23
    Is there any patch build that contains a fix for this? Thanks.
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Not yet.
     
  6. PHohmeyer

    PHohmeyer

    Joined:
    Apr 13, 2017
    Posts:
    1
    There's a different issue here as well. In the case reported by sergey, WWW.responseHeaders does not return null, trying to access it throws an exception.

    As far as I can tell, accessing WWW.responseHeaders will throw a NullReferenceException if the response body is empty, even if there are response headers.
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Correct. This is the other bug, a fix is in the pipeline, will come out soon.
     
  8. VirZOOM

    VirZOOM

    Joined:
    Mar 16, 2017
    Posts:
    4
    We're interested in these fixes as well, thank you
     
  9. aahinoam

    aahinoam

    Joined:
    Jul 11, 2016
    Posts:
    1
    We need it too.
     
  10. SergioMira-Swrve

    SergioMira-Swrve

    Joined:
    Mar 20, 2013
    Posts:
    3