Visual Source Safe API and history operation already in progress

I am writing a application that will take some projects from one VSS database, store them on a disk do something with the files and then copy those files to another VSS database.
So I was trying to get the latest version of a file from the VSS using the following code (inside a foreach loop):
IEnumerator versions = vssFile.get_Versions ( 0 ).GetEnumerator();
versions.MoveNext ();
int latestVersion = ((IVSSVersion)versions.Current).VersionNumber;
(yes I know what generics are, but VSS API does not support them...)
anyways while this was in a test code outside of some loop everything worked fine. But then I started writing the real code and I got the error from the title of this post.
After some time spent on google I found out that VSS 6.0 (this is fixed in VSS2005) has a "feature" that you have to iterate trough the whole collection in order for it to dispose itself correctly. And the error was caused because you can't have more than one "get_Versions" operation at the time and the collection was not disposed after the loop got to the next iteration.
So if you only need the first item from the colletion (the latest version), your code has to look something like this:
foreach ( IVSSItem vssFile in currentVssProject.get_Items ( false ) )
{
System.Collections.IEnumerator versions = vssFile.get_Versions ( 0 ).GetEnumerator();
versions.MoveNext ();
int latestVersion = ((IVSSVersion)versions.Current).VersionNumber;
while ( versions.MoveNext () ) {}

// do the magic
}
Avtor: Anonymous, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.