cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error reading file async

Error reading file async

Lukag
Collaborator | Level 8

I had a problem to download a file ( an Image ) and someone recommended to me to do asynchronously.

I changed my code so : 

 Async Function _take_file(ByVal _file As String) As Task

....

Dim client As HttpClient = New HttpClient()

Dim _Request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, "https://content.dropboxapi.com/2/files/download")
_Request.Headers.Add("Authorization", "Bearer " + _token)
_Request.Headers.Add("Dropbox-API-Arg", _parametro)

Dim _response As HttpResponseMessage = Await client.SendAsync(_Request)

Dim _responseStream As Stream = Await _response.Content.ReadAsStreamAsync()
Dim myStreamReader As New StreamReader(_responseStream)

 

I have an error on the last line : 

System.NullReferenceException was unhandled
Message: An unhandled exception of type 'System.NullReferenceException' occurred in mscorlib.dll

11 Replies 11

Здравко
Legendary | Level 20

@Lukag wrote:

...
Dim myStreamReader As New StreamReader(_responseStream)

...


Hm..🤔 Let's see what's going on here. Does the 'myStreamReader' variable get declared here, or get value assigned, or...? 🧐

Lukag
Collaborator | Level 8

Hm both ? 

i thought that it  declared and that got value. 

Здравко
Legendary | Level 20

@Lukag wrote:

...

Dim client As HttpClient = New HttpClient()

...
Dim myStreamReader As New StreamReader(_responseStream)

...


Then, what's different and common in above code lines (aside of different types)?

Lukag
Collaborator | Level 8

In first case a define the object and i create as a new httpclient

in the second i declare ad object as a new streamreader using data from response .

In the code of example i see i thought it works so 🙂 

Здравко
Legendary | Level 20

Your error message means that in your code you have used something not initialized at that time. That's it.

Lukag
Collaborator | Level 8

Yes but i don't understand.

.

First of all, in you opinion is correct use streamreader ? 

I don't want become crazy and after i have other problems 🙂

 

Здравко
Legendary | Level 20

@Lukag wrote:

...

First of all, in you opinion is correct use streamreader ? 

...


What you use is matter of design decision, so don't ask anybody else. The best way follows what you're doing. If you don't know what are you doing... no way to decide what's the best (or even to suppose).

Such questions are not Dropbox API related though. If you have something to learn about programing lang in use, read some tutorial or similar.

Lukag
Collaborator | Level 8

i'm learning and reading guides and tutorial but the error made me worry that API  were missing something and so I asked for your help

Здравко
Legendary | Level 20

🙂 Ok. Where is the API related error, mistake, mismatching, etc? What are you getting as error response? What is the status code? All are questions, you have to answer, and one of them at least have to be related to Dropbox API (the same for any other API)!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Lukag Collaborator | Level 8
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?