-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p4Info task throws System.NullReferenceException - BUG #29
Comments
Hi, thanks for the hint. What's your proposal now? |
There might be several reasons for this. However, I suspect one of the properties is null in the context I'm running the p4 command. protected override void ExecuteTask()
{
string[] find = {"User name:", "Client name:", "Client host:", "Client root:"};
string[] results = Perforce.GetP4Info(find);
if(results == null) throw new Exception(“Failed to retrieve P4 info.”);
Project.Properties[User] = results.Length > 0 ? results[0] : “unknown”;
Project.Properties[Client] = results.Length > 1 ? results[1] : “unknown”;
Project.Properties[Host] = results.Length > 2 ? results[2] : “unknown”;
Project.Properties[Root] = results.Length > 3 ? results[3] : “unknown”;
} |
Also, It might be useful to add a parameterized task GetP4Info for retrieving individual info fields. |
Hi, Could you please show me your output of your |
Assuming the “results” array is not null, not calling ToString() on each element would help in the sense it would retrieve the maximum information available instead of throwing a NullReferenceException. It's a good practice to implement validation in your code instead of relying on what thirdparty developers say. This issue itself shows why the best. That is the reason for additional checks to the length and results not being null. You never know in what context people may run it in the future. I use standard version I believe. Here’s the output my p4 info cmd line (I changed the environment specific values). It seems the Client Root is not there for some reason. C:\Documents and Settings\user1>p4 info C:\Documents and Settings\user1> |
p4Info executes ToString() on the values Perforce.GetP4Info(find) returns without checking if ithey are not nulls. Taking into account that Perforce.GetP4Info(find) returns an array of string it's not needed at all and introduces a bug only.
protected override void ExecuteTask()
{
string[] find = {"User name:", "Client name:", "Client host:", "Client root:"};
string[] results = Perforce.GetP4Info(find);
}
The text was updated successfully, but these errors were encountered: