JohnnyCrazy / SpotifyAPI-NET

:sound: A Client for the Spotify Web API, written in C#/.NET
http://johnnycrazy.github.io/SpotifyAPI-NET/
MIT License
1.5k stars 305 forks source link

System.NullReferenceException after multiple times #33

Closed JimmyAppelt closed 9 years ago

JimmyAppelt commented 9 years ago

Using the SpotifyAPI.Local

When doing _spotify.GetStatus() after series of time, like i would like to do in a timer.

Every 1 second or 2 seconds or so, the object is not null but the track seems to be null very often.

My purpose is to check spotify very often if there is a new song playing.

I'm binding the Artistname like so:

var o = _spotify.GetStatus(); label.text = o.Track.ArtistResource.Name;

It will spam with NullReferenceException when i try to work with a timer, so the artist and etc. will not update for a pretty long time.

JohnnyCrazy commented 9 years ago

Could you give me some information about the interval you are querying? There was an issue, where GetStatus would return null after about 10 Minutes running, but this should be resolved by the new spotify client introduced.

JimmyAppelt commented 9 years ago

I tried with 1000 - 2000 - 3000 - 5000 milliseconds

For example trying to do this withing a timer calling my GetSpotifyTrackInfo() method:

    private void GetSpotifyTrackInfo()
    {
        _spotify.Connect();
        var o = _spotify.GetStatus();
        textBoxArtist.Text = o.Track.ArtistResource.Name;
        textBoxSong.Text = o.Track.TrackResource.Name;
        pictureBoxAlbum.ImageLocation = o.Track.GetAlbumArtUrl(AlbumArtSize.Size320);
    }

The object o is not null, but the Track object inside o object returns null - lets say 8 out of 10

JohnnyCrazy commented 9 years ago

You should not call the Connect-Method every time you query, just do it one time when your app starts. Try connecting in the constructor and remove the call in the method and see if it works :)

JimmyAppelt commented 9 years ago

Ah right :)

I was trying to make my app so it connects automatically to spotify if it is opened after my application starts.

Seems it works fine like you said.

Thanks for swift response !

JohnnyCrazy commented 9 years ago

No Problem, feel free to open another issue if you have any further problems! :+1: