Great work and a bug report

Aug 17, 2011 at 8:27 AM


First I would like to say that Sharpotify has really helped us integrating with Spotify, so thanks alot!

But I have found a few bugs / issues with Sharpotify though:

  • Using IPv6 doesn't work. Sorry for not having more info about this issue, but at the time I hadn't downloaded the source code yet!
  • Parsing the query result XML throws and NullReferenceException, insted of XMLParsingException when parsing tracks (due to the unknown element <alternatives>. What about not throwing an exception but instead skipping unknown tags (writing to debug output if encounted)?
  • From time to time an exception is thrown when our testers runs the application. I haven't had the time to take a closer look at this yet but here's the stacktrace.
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.Collections.Generic.KeyNotFoundException
       at Sharpotify.Protocol.Channel.Channel.Process(Byte[])
       at Sharpotify.SpotifyConnection.CommandReceived(Int32, Byte[])
       at Sharpotify.Protocol.Protocol.OnReceivePacketHeaderReceived(System.IAsyncResult)
       at System.Net.LazyAsyncResult.Complete(IntPtr)
       at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
       at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
       at System.Net.ContextAwareResult.Complete(IntPtr)
       at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
       at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
 I'll get back to you if I found anything. 

Aug 17, 2011 at 5:06 PM

Back home I took a look at last issue and it seems like this is the problem:

/* Get Channel by id from payload. */
if ((channel = Channel._channels[ShortUtilities.BytesToUnsignedShort(payload)]) == null)
    /* Just return if channel is not registered. */

 which will cast a KeyNotFoundException if the channelId (extracted from the payload) is not found. I've implemented this solution:

ushort channelId = ShortUtilities.BytesToUnsignedShort(payload); /* Get Channel by id from payload. */
Channel channel = Channel._channels.ContainsKey(channelId) ? Channel._channels[channelId] : null;

if (channel == null)
    /* Just return if channel is not registered. */

As it seems like no action should be done anyway if channel id isn't registrated.



Aug 23, 2011 at 10:21 AM

Hi Joakim, and thank you very much!

About the Ipv6 support i'm not working neither planned it. Sorry.

The "alternatives" xml section, it's a new parameter from the Spotify people. It should be parsed in the same way as "similar-tracks".

And I would like to thank you again for the fix of the issue you notified before.

Currently, in my free time, i'm working in the sharpotify7 project (the port to Windows Phone 7) and i have forgotten the maintenance of the original sources. But as soon as i can, i will update the source code.