I’ve got a bit of code that is giving me some trouble.
I’m trying to bundle a list of images into a zip file. The problem I’m having is that, on occasion, one of the images will be opened when it is accessed, causing an exception.
I’m pretty sure it’s a timing issue, so I’m coding a ‘second chance’ loop to catch the images that fall through (as opposed to the existing behavior, where it halts on any error and gives back what it has thusfar).
I have the potentially erroring sections of code in a try block, as seen below
if (!Directory.Exists(physicalPath + "/" + fi.Description))
{
Directory.CreateDirectory(physicalPath + "/" + fi.Description);
}
wc.DownloadFile(source, physicalPath + "/" + fileName);
ze = zip.AddFile(physicalPath + "/" + fileName, path);
ze.FileName = fileName;
‘ze’ is a ‘ZipEntry’ from the Ionic.Zip library, and ‘wc’ is a WebClient.
In my catch, I need to store two pieces of information: ‘source’ and the string that results from ‘physicalPath + “/” + filename’.
I know there’s a way in .NET 4 to dynamically create a new object to hold this data, but I don’t recall what it’s called. This has greatly hampered my google-fu.
How can I create a dynamic object that will hold a pair of strings (preferably with property names on the variables) without creating a whole new class?
Are you referring to a Tuple?
http://msdn.microsoft.com/en-us/library/system.tuple.aspx