SPFile.Versions.GetVersionFromId or SPFile.Versions.GetVersionFromLabel might not return the desired version of a file. But when you iterate through all the versions and then check for versionId, then we get the desired SPFileVersion which is not null. So apparently, this is a bug in the API.
//this might not work all the times as it wil fail to retrieve some of the versions of a file
//especially with Published major version when there are minor versions also present.
SPFile file=web.GetFile(itemUrl);
SPFileVersion fileVersion=file.Versions.GetVersionFromId(1024) //Here the fileVersion may be null
//where as this works fine
SPFile file=web.GetFile(itemUrl);
SPFileVersion fileVersion=null;
foreach(SPFileVersion ver in file.Versions)
{
if(ver.ID==1024)
{
fileVersion=ver;
break;
}
}