C# Perforce P4 API: Client.GetSyncedFiles causes an exception

Viewed 165

I'm trying to view files in my workspace, eventually I want to use GetSyncedFiles() to simply view the current state of the files and what revision it is so I can alert the user. But I can't perform the most simple operation with no flags.

The message to the exception is "GetSyncedFiles has no valid options\r\nParameter name: options".

I've tried omitting the file list and setting different flags in the options, always the same result.

try
{
    Perforce.P4.Server srv = new Perforce.P4.Server(new ServerAddress(PerforceServer + ":" + PerforcePort));
    Repository epo = new Perforce.P4.Repository(srv);
    repo.Connection.UserName = PerforceUser;
    repo.Connection.SetClient(PerforceWorkspace);
    repo.Connection.Client.Name = PerforceWorkspace;
    repo.Connection.Connect(new Perforce.P4.Options());
    repo.Connection.Login(PerforcePassword);

    List<FileSpec> fileSpecs = new List<FileSpec>();
    foreach (var filename in Directory.GetFiles(DirectoryWithTargetFiles))
    {
        fileSpecs.Add(new FileSpec(new ClientPath(filename)));
    }

    SyncFilesCmdOptions cmdFlags = new SyncFilesCmdOptions(SyncFilesCmdFlags.None);
    FileSpec[] fsa = fileSpecs.ToArray();
    var someFiles = m_repo.Connection.Client.GetSyncedFiles(cmdFlags, fsa);//execution gets to here
}
catch (Perforce.P4.P4Exception e)
{
    Console.WriteLine(e.Message);
}
catch (Exception ee)
{
    //this exception will hit
    Console.WriteLine(ee.Message);
}
2 Answers

From the source code of the Perforce .NET API in the GitHub repository:

public IList<FileSpec> GetSyncedFiles(Options options, params FileSpec[] files)
    {
        if (options != null)
        {
            throw new ArgumentException("GetSynchedFiles has no valid options", "options");
        }
        return runFileListCmd("have", options, files);
    }

It can be noticed that if the options is anything other than null, it throws an ArgumentException. Hence, in order for this to work, you have to pass null for the options:

var someFiles = m_repo.Connection.Client.GetSyncedFiles(null, fsa);

Also, the second overload redirects it to the same method:

public IList<FileSpec> GetSyncedFiles(IList<FileSpec> toFiles, Options options)
    {
        return GetSyncedFiles(options, toFiles.ToArray<FileSpec>());
    }
Related