I have an exception when calling Workspace.Merge
. I am getting access to VersionControlExt
from VisualStudio. The code below gets access to Visual Studio TFS explorer window object (that is active in the environment and user is logged in).
VersionControlExt vce;
vce = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
MergeCandidate[] candidates = version.GetMergeCandidates(source, dest, RecursionType.Full);
Workspace ws = vce.Explorer.Workspace;
foreach (MergeCandidate mc in candidates)
{
string comment = mc.Changeset.Comment;
ChangesetVersionSpec csvs = new ChangesetVersionSpec(mc.Changeset.ChangesetId);
// HERE NULL REFERENCE EXCEPTION IS THROWN
GetStatus gs = ws.Merge(source, dest, csvs, csvs, LockLevel.None, RecursionType.Full, MergeOptionsEx.None);
}
Exception Details
TargetSite: {System.String get_AuthorizedUser()}
StackTrace
at Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer.get_AuthorizedUser()\r\n at Microsoft.TeamFoundation.VersionControl.Client.Workspace.get_DisplayName()\r\n at Microsoft.TeamFoundation.VersionControl.Client.Workspace.RequireLocal()\r\n at Microsoft.TeamFoundation.VersionControl.Client.Workspace.Merge(ItemSpec source, String targetPath, VersionSpec versionFrom, VersionSpec versionTo, LockLevel lockLevel, MergeOptionsEx mergeOptions, String[] propertyNameFilters)\r\n at Microsoft.TeamFoundation.VersionControl.Client.Workspace.Merge(ItemSpec source, String targetPath, VersionSpec versionFrom, VersionSpec versionTo, LockLevel lockLevel, MergeOptionsEx mergeOptions)\r\n at Microsoft.TeamFoundation.VersionControl.Client.Workspace.Merge(String sourcePath, String targetPath, VersionSpec versionFrom, VersionSpec versionTo, LockLevel lockLevel, RecursionType recursion, MergeOptionsEx mergeOptions)\r\n
Found the problem. In order to use TFS functionality one needs to reference Microsoft.TeamFoundation.VersionControl.Client.dll. I have both 9.0 Studio and 10.0 Studio installed. I have referenced dlls from 10.0 while actually using 9.0 studio. Stupid mistake but it has taken hours to debug.