A DotNet variable has not been instantiated. System.Net.WebResponse.GetResponseStream

CGaraldeCGaralde Member Posts: 19
Hi,

I have some code which I use to log API errors in NAV and it was working until yesterday. I have Googled this "instantiated" error and I read that I should call the constructor first but for the life of me I cannot understand what it means.

So from what I understand, the GetResponseStream here is the method, which one is the constructor that I need to call first then?
Exception := GETLASTERROROBJECT;
    WebException := Exception.InnerException; 
    Response := WebException.Response;
    Response.GetResponseStream; //error here
    StreamReader := StreamReader.StreamReader(Response.GetResponseStream);
    ReqString := StreamReader.ReadToEnd;
Name	DataType	Subtype	Length
Exception	DotNet	System.Exception.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
WebException	DotNet	System.Net.WebException.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
Response	DotNet	System.Net.WebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
StreamReader	DotNet	System.IO.StreamReader.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
ReqString	DotNet	System.String.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'


I am asking this question in my head and it seems silly but I would appreciate any input.

Answers

  • tabrezajaz@hotmail.com[email protected] Member Posts: 2
    Hi CG,

    Refer below .net example to understand:
    https://docs.microsoft.com/en-us/dotnet/api/system.net.webresponse.getresponsestream?view=net-5.0

    something like the below declaration in C#:
    // Obtain a 'Stream' object associated with the response object.
    Stream ReceiveStream = myWebResponse.GetResponseStream();
  • CGaraldeCGaralde Member Posts: 19
    Hi tabrezajaz,


    First of all, thanks for taking the time to look into my post.

    I actually tried this just after I posted the question to see if it made any difference, unfortunately I am still getting the same error:
    Exception := GETLASTERROROBJECT;
        WebException := Exception.InnerException; 
        Response := WebException.Response;
        Stream := Response.GetResponseStream;
        StreamReader := StreamReader.StreamReader(Stream);
        ReqString := StreamReader.ReadToEnd;
    
    Name	DataType	Subtype	Length
    Exception	DotNet	System.Exception.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    WebException	DotNet	System.Net.WebException.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Response	DotNet	System.Net.WebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Stream	DotNet	System.IO.Stream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    StreamReader	DotNet	System.IO.StreamReader.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ReqString	DotNet	System.String.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    
Sign In or Register to comment.