This project has moved and is read-only. For the latest updates, please go here.

Flickr.PhotosSearch throwing an exception (input string not in correct format) in C#

Topics: Developer Forum, Project Management Forum, User Forum
Mar 14, 2014 at 6:50 PM

I am running my code on a Windows 7 64-bit machine, Visual Studio 2012 and Flickr.Net dll version 3.10 (latest)

Below is a snippet of my code which should summarize the problem:

Flickr flickr = new Flickr ("MyKey"); // MyKey is my Flickr Key
PhotoSearchOptions options = new PhotoSearchOptions();
PhotoCollection photos = new PhotoCollection();


photos = flickr.PhotosSearch(options);
// After this statement I get the exception which on handling yields the following output:

Input string was not in a correct format.
Source: mscorlib
Stack Trace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Int64.Parse(String s, NumberStyles style, IFormatProvider provider)
at FlickrNet.ResponseCacheItemPersister.Read(Stream inputStream)
at FlickrNet.PersistentCache.Load(Stream s)
at FlickrNet.PersistentCache.Refresh()
at FlickrNet.PersistentCache.Get(String key, TimeSpan maxAge, Boolean removeIfExpired)
at FlickrNet.Flickr.GetResponse[T](Dictionary2 parameters, TimeSpan cacheTimeout)
at FlickrNet.Flickr.GetResponseCache[T](Dictionary
2 parameters)
at FlickrNet.Flickr.PhotosSearch(PhotoSearchOptions options)

Can someone please help me out here ? I would appreciate it.
Mar 15, 2014 at 2:19 PM
Looks like the cache has got corrupt somehow. Try finding the cache location (check the CacheLocation property) and delete the cache.

Marked as answer by sportsfreak on 3/17/2014 at 9:11 PM
Mar 18, 2014 at 5:10 AM
Thank you. This did work. It does fetch the images using PhotosSearch.
However, I failed to perform a search based on MinTaken/MaxTaken or MinUpload/MaxUpload dates (search for images based on min date taken or min upload dates, etc. )
It would always yield the same set of images each time I try a different date (i.e. the dates on each of these images are 0001-01-01)
Any clue on this ?
Mar 18, 2014 at 11:58 AM
The date fields is only set if you ask for them, using the Extras parameter:
var options = new PhotoSearchOptions();
options.Extras = PhotoSearchExtras.DateTaken | PhotoSearchExtras.DateUploaded 
Mar 25, 2014 at 7:14 PM
I am confused and cannot figure out how does this statement help
options.Extras = PhotoSearchExtras.DateTaken | PhotoSearchExtras.DateUploaded

From what I understand it returns the DateTaken and DateUploaded parameters and sets it to Extras.
But how does it do that before searching (PhotosSearch) for the images ? If possible, could you please elaborate a bit more on this ?

For e.g. Say I need to search for images within the following timespan:
MinDateTaken= 1/1/2013
MaxDateTake= 1/1/2014

How do I set these parameters in options and subsequently instruct flickr.PhotosSearch to retrieve images taken between these dates ?
Mar 25, 2014 at 11:05 PM
Setting the "Extras" property tells Flickr which extra data it should send back in the REST API call. If you don't ask for this data then the data will be blank (or in the case of DateTime fields they will be effectively zero (as DateTime is a value type, and not a reference type, hence cannot be null).
Flickr flickr = new Flickr ("MyKey"); 

PhotoSearchOptions options = new PhotoSearchOptions(); 

options.Extras = PhotoSearchExtras.DateTaken | PhotoSearchExtras.DateUploaded;
options.MinDateTaken = new DateTime(2013,1,1);
options.MaxDateTaken = new DateTime(2014,1,1);

PhotoCollection photos = flickr.PhotosSearch(options); 
Marked as answer by sportsfreak on 3/26/2014 at 7:42 AM
Apr 2, 2014 at 6:13 PM
Thank you so much for your help.
This worked out well. Appreciate it.