I'm facing a weird issue with SharePoint 2010 user profile.
I'm storing in the user profile a base 64 string that hold some custom data. As the data may be quite heavy, the profile property has been set to allow multiple string values.
However, when the string starts to grow significantly, SharePoint starts to alter the string values. In my case, a single "S" is transformed to a "s". And after that, as I'm deserializing the string, this make the whole thing to crash.
I was not able to understand when does it occurs, but I have written a small reproduction code :
[TestMethod()]
public void ImportFromJson3Test()
{
string b64 =
"AAEAAAD/////AQAAAAAAAAAMAgAAAFVTb1NQLkNHNDIuSW50cmFuZXQsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFs" +
"LCBQdWJsaWNLZXlUb2tlbj1kY2IxY2UxYmRmYzMwMjUyBAEAAAC2AVN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljLkxpc3RgMVtb" +
"U29TUC5DRzQyLkludHJhbmV0LldlYlBhcnRzLk15TGlua3NXZWJQYXJ0LlBPQ08uQmFzZUVudGl0eSwgU29TUC5DRzQyLkludHJh" +
"bmV0LCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49ZGNiMWNlMWJkZmMzMDI1Ml1dAwAA" +
"AAZfaXRlbXMFX3NpemUIX3ZlcnNpb24EAAA8U29TUC5DRzQyLkludHJhbmV0LldlYlBhcnRzLk15TGlua3NXZWJQYXJ0LlBPQ08u" +
"QmFzZUVudGl0eVtdAgAAAAgICQMAAAASAAAAAgAAAAcDAAAAAAEAAAAsAAAABDpTb1NQLkNHNDIuSW50cmFuZXQuV2ViUGFydHMu" +
"TXlMaW5rc1dlYlBhcnQuUE9DTy5CYXNlRW50aXR5AgAAAAkEAAAACQUAAAAJBgAAAAkHAAAACQgAAAAJCQAAAAkKAAAACQsAAAAJ" +
"DAAAAAkNAAAACQ4AAAAJDwAAAAkQAAAACREAAAAJEgAAAAkTAAAACRQAAAAJFQAAAAkWAAAACRcAAAAJGAAAAAkZAAAACRoAAAAJ" +
"GwAAAAkcAAAACR0AAAA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AAAA5odHRwOi8vc29zcC5mcgG6////" +
"z////1vgAiwiOVpLu0U9cl/dxgAGRwAAAAZzb3NwMzYBDAAAAAQAAAAGSAAAAA5odHRwOi8vc29zcC5mcgG3////z////2dIVXeD" +
"Ut1CqNKg6Rffs6sGSgAAAAZzb3NwMzUBDQAAAAQAAAAGSwAAAA5odHRwOi8vc29zcC5mcgG0////z////65X8UZuvjhEuSLIoaOw" +
"lKsGTQAAAAZzb3NwMzQBDgAAAAQAAAAGTgAAAA5odHRwOi8vc29zcC5mcgGx////z////8jjMeORKX1Lg7UV06evnzUGUAAAAAZz" +
"b3NwMzMBDwAAAAQAAAAGUQAAAA5odHRwOi8vc29zcC5mcgGu////z////yoLo/IktWVHvK8R9g8Z+UQGUwAAAAZzb3NwMzIBEAAA" +
"AAQAAAAGVAAAAA5odHRwOi8vc29zcC5mcgGr////z////1be7zBvcLpCmkKeY0/8JlAGVgAAAAZzb3NwMzEBEQAAAAQAAAAGVwAA" +
"AA5odHRwOi8vc29zcC5mcgGo////z////+SXnzOmi9FDl5VbfjJZa6gGWQAAAAZzb3NwMzABEgAAAAQAAAAGWgAAAA5odHRwOi8v" +
"c29zcC5mcgGl////z////61G9H2DdM9EvvDTIIEG050GXAAAAAZzb3NwMjkBEwAAAAQAAAAGXQAAAA5odHRwOi8vc29zcC5mcgGi" +
"////z////7zW8a7QULpIuMBaM2NU5DgGXwAAAAZzb3NwMjgBFAAAAAQAAAAGYAAAAA5odHRwOi8vc29zcC5mcgGf////z////5ya" +
"8MNyBLpDg8a9aSm9YkQGYgAAAAZzb3NwMjcBFQAAAAQAAAAGYwAAAA5odHRwOi8vc29zcC5mcgGc////z////8khACJhlYpNtDam" +
"N3J4osMGZQAAAAZzb3NwMjYBFgAAAAQAAAAGZgAAAA5odHRwOi8vc29zcC5mcgGZ////z////5HaoYWJOz5OnTDMUQEhAhEGaAAA" +
"AAZzb3NwMjUBFwAAAAQAAAAGaQAAAA5odHRwOi8vc29zcC5mcgGW////z////0i2gFTJQaZAp8rsEi6r3xEGawAAAAZzb3NwMjQB" +
"GAAAAAQAAAAGbAAAAA5odHRwOi8vc29zcC5mcgGT////z////69Din/hIPVIlVBFK/heBqgGbgAAAAZzb3NwMjMBGQAAAAQAAAAG" +
"bwAAAA5odHRwOi8vc29zcC5mcgGQ////z/////wOkE7aTuxIhMZ2tLlJUysGcQAAAAZzb3NwMjIBGgAAAAQAAAAGcgAAAA5odHRw" +
"Oi8vc29zcC5mcgGN////z////0WSzWpq0JBEun5GFfi0AnUGdAAAAAZzb3NwMjEBGwAAAAQAAAAGdQAAAA5odHRwOi8vc29zcC5m" +
"cgGK////z////8ZdEibE7RdGqCA5DT4uXOsGdwAAAAZzb3NwMjABHAAAAAQAAAAGeAAAAA5odHRwOi8vc29zcC5mcgGH////z///" +
"/yzc8otZ4K9OpyEpX+Mf8YoGegAAAAZzb3NwMTkBHQAAAAQAAAAGewAAAA5odHRwOi8vc29zcC5mcgGE////z////4AuqijW/xRP" +
"n8FwIETBAE8GfQAAAAZzb3NwMTgBHgAAAAQAAAAGfgAAAA5odHRwOi8vc29zcC5mcgGB////z////2ZR1x2qqnBAlKsM8Cu/ElEG" +
"gAAAAAZzb3NwMTcBHwAAAAQAAAAGgQAAAA5odHRwOi8vc29zcC5mcgF+////z////47Q3VWxc11Pv9UDEiLwU6YGgwAAAAZzb3Nw" +
"MTYBIAAAAAQAAAAGhAAAAA5odHRwOi8vc29zcC5mcgF7////z////+0wWflym8JFiUl8RyI6bSUGhgAAAAZzb3NwMTUBIQAAAAQA" +
"AAAGhwAAAA5odHRwOi8vc29zcC5mcgF4////z////xi1jdHkS55EuCov9WyjfGgGiQAAAAZzb3NwMTQBIgAAAAQAAAAGigAAAA5o" +
"dHRwOi8vc29zcC5mcgF1////z////7ZzzL1ThF9IpZCO+Bd+adcGjAAAAAZzb3NwMTMBIwAAAAQAAAAGjQAAAA5odHRwOi8vc29z" +
"cC5mcgFy////z////4cZ8/EMPzRKlBQ9jUjUerYGjwAAAAZzb3NwMTIBJAAAAAQAAAAGkAAAAA5odHRwOi8vc29zcC5mcgFv////" +
"z////x3jdau8OERCltBnr6KRkcsGkgAAAAZzb3NwMTEBJQAAAAQAAAAGkwAAAA5odHRwOi8vc29zcC5mcgFs////z////1qNe+3f" +
"LJ5EtZhWzr/Bcb0GlQAAAAZzb3NwMTABJgAAAAQAAAAGlgAAAA5odHRwOi8vc29zcC5mcgFp////z////wSspqzj/BdOhES74OcG" +
"p+oGmAAAAAVzb3NwOQEnAAAABAAAAAaZAAAADmh0dHA6Ly9zb3NwLmZyAWb////P////fx0ShxPJhUKDCD7ioAaEXgabAAAABXNv" +
"c3A4ASgAAAAEAAAABpwAAAAOaHR0cDovL3Nvc3AuZnIBY////8////+dZNSBpNJsSK7dGh9RD1wABp4AAAAFc29zcDcBKQAAAAQA" +
"AAAGnwAAAA5odHRwOi8vc29zcC5mcgFg////z////4AJ6irtVYZNmUfJH5NSDeQGoQAAAAVzb3NwNgEqAAAABAAAAAaiAAAADmh0" +
"dHA6Ly9zb3NwLmZyAV3////P////8L90EyjU1kGfilAPmR1zygakAAAABXNvc3A1ASsAAAAEAAAABqUAAAAOaHR0cDovL3Nvc3Au" +
"ZnIBWv///8////+2T8PkV5rzS58pDtQco1eJBqcAAAAFc29zcDQBLAAAAAQAAAAGqAAAAA5odHRwOi8vc29zcC5mcgFX////z///" +
"/8wQJ7BLuD5Mk/MOSJuqKDwGqgAAAAVzb3NwMwEtAAAABAAAAAarAAAADmh0dHA6Ly9zb3NwLmZyAVT////P////L5nUfHcK8k27" +
"2Mgt6Ex+NAatAAAABXNvc3AyAS4AAAAEAAAABq4AAAAOaHR0cDovL3Nvc3AuZnIBUf///8////+rZH1GGG0sSI5W6b6IuIAjBrAA" +
"AAAFc29zcDEBLwAAAAQAAAAGsQAAAA5odHRwOi8vc29zcC5mcgFO////z////wEUPTdIN99CrSfeD0Q8OBQGswAAAAVzb3NwMAs=";
string[] b64Arr = Split(b64, 255).ToArray();
using (var site = new SPSite("http://someserver/sites/somesite"))
{
using (var web = site.OpenWeb(""))
{
var user = web.EnsureUser(@"domain\user");
var profile = user.GetProfile();
var prop = profile.GetProfileValueCollection("MyLinks");
prop.Clear();
foreach (var item in b64Arr)
{
prop.Add(item);
}
profile.Commit();
}
}
using (var site = new SPSite("http://someserver/sites/somesite"))
{
using (var web = site.OpenWeb(""))
{
var user = web.EnsureUser(@"domain\user");
var profile = user.GetProfile();
var result = profile.GetProfileValueCollection("MyLinks").Cast<string>().ToList();
CollectionAssert.AreEqual(b64Arr.ToList(), result);
}
}
}
private static IEnumerable<string> Split(string str, int chunkSize)
{
int numberRead = 0;
while (true)
{
var remaining = str.Substring(numberRead);
if (remaining.Length <= chunkSize)
{
yield return remaining;
break;
}
else
{
yield return remaining.Substring(0, chunkSize);
numberRead += chunkSize;
}
}
}
public static UserProfile GetProfile(SPUser user)
{
if (user == null) throw new ArgumentNullException("user");
var spc = SPServiceContext.GetContext(user.ParentWeb.Site);
var mgr = new UserProfileManager(spc);
if (mgr.UserExists(user.LoginName))
{
return mgr.GetUserProfile(user.LoginName);
}
else
{
return null;
}
}
In order to run this test, first create a user profile property "MyLinks", of type string and that accepts multiples values.
You should also specify a user that have a profile.
Does anyone has yet faced such issue? How did you solved it?
PS: cross posted on MSDN forum