Reputation: 725
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);
}
Upvotes: 2
Views: 466
Reputation: 4939
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>());
}
Upvotes: 1
Reputation: 27065
My guess would be that an empty option object is marked as invalid:
If you look at the documentation, the option has many many subclasses that override the default option class https://www.perforce.com/manuals/p4api.net/p4api.net_reference/html/T_Perforce_P4_Options.htm
Have you tried any of those options like this one? Or have you tried just passing null? or omitting the line?
repo.Connection.Connect(new Perforce.P4.Options());
Upvotes: 1