VidasV
VidasV

Reputation: 4895

TF20507: The string argument contains a character that is not valid:'u0009'. Correct the argument, and then try the operation again

I started getting this error when calling ReadIdentities... After updating from Visual studio 2010 to 2012 SDK. It crashes due to invalid "\t" in one of the members. (New validation rules in TFS API probably).

var GSS = tfs.GetService<IIdentityManagementService>();

Identity SIDS = project.GSS.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Members", QueryMembership.Expanded);
var _TFSUsers = project.GSS.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.None);

The saddest part of this story is that I need to find out which member has this tab char. And TFS contains 2000+ members. I tried running one by one, but only ReadIdentities method crashes. ReadIdentity passes. So decided to follow these steps:

foreach (var memberSID in SIDS.Members)
                {
                    try
                    {
                        var identity = project.GSS.ReadIdentities(SearchFactor.Sid,new string[] { memberSID,}, QueryMembership.None);

                    }
                    catch (Exception ex2)
                    {
                        throw new InvalidOperationException("Failed to load TFS user: " + memberSID, ex2);
                    }
                }

Yet somehow this did not work either! As the code ran flawlessly with no exceptions.

Upvotes: 2

Views: 9703

Answers (2)

Ashu
Ashu

Reputation: 429

I know its bit late but I hope this will help someone. If its really tab issue with this error message. You can try below step.

  1. Open your code file in Visual studio code or just past your code in new file. enter image description here
  2. Then press shift+ctrl+P
  3. Select Convert indentation to Space enter image description here

Upvotes: 3

VidasV
VidasV

Reputation: 4895

I have produced the method which splits the array half and tries to narrow the search until the smallest possible size.

private static void SplitHalf(string[] identities, IIdentityManagementService GSS)
        {
            var count = identities.Count();
            int half = count / 2;
            List<string> half1 = new List<string>();
            List<string> half2 = new List<string>();

            for (int i = 0; i < half; i++)
            {
                half1.Add(identities[i]);
            }

            var halfArray1 = half1.ToArray();

            try
            {
                var users = GSS.ReadIdentities(SearchFactor.Sid, halfArray1, QueryMembership.None);
            }
            catch (Exception ex)
            {
                SplitHalf(halfArray1, GSS);
            }

            for (int i = half; i < count; i++)
            {
                half2.Add(identities[i]);
            }

            var halfArray2 = half2.ToArray();

            try
            {
                var users = GSS.ReadIdentities(SearchFactor.Sid, halfArray2, QueryMembership.None);
            }
            catch (Exception ex)
            {
                SplitHalf(halfArray2, GSS);
            }
        }

This way, I was able to put breakpoint with condition count == 2. And narrowed down to find out the display name and identity that was crashing the stuff. I hope this saves some time for someone. It appears that crashing occurs only when minimum of two SIDS are supplied for the method parameters, supplying only one, did not result in error...

Upvotes: 1

Related Questions