Search code examples
c#perforcep4api.net

Cannot retrieve perforce clients


I am trying to develop a C# based build tool using p4api.net apis. I am new to perforce p4api.net. I followed the instructions given in p4api.net library downloaded from their site, but was never successful in running a basic command on perforce. I am attaching piece of code which is supposed to fetch clients from Perforce. Please correct it, if am wrong. The code throws a run time error (unhandled expection) while executing GetClients().

static void Main(string[] args)
{
    string uri = "perforce:1666";
    string user = "User1";

    Server server = new Server(new ServerAddress(uri));
    Repository rep = new Repository(server);
    Connection con = rep.Connection;

    con.UserName = user;
    con.Client = new Client();

    // connect to the server
    con.Connect(null);

    // run the command against the current repository
    IList<Client> changes = rep.GetClients(null);
}

Any useful guide to perforce C# documents/examples would be appreciated.

Thanks, Madhu


Solution

  • Are you sure that the exception is coming from GetClients? I ran your code successfully, but when I changed uri to a non-existent server:port I get the unhandled exception at con.Connect(null).

    Confirm that you do have access to a perforce:1666 server with User1 and that User1 does not require a password on that server.