我正在使用Microsoft代碼在用戶配置文件服務器中創建新組織,如http://msdn.microsoft.com/en-us/library/ms545122.aspx。CreateOrganizationProfile錯誤對象引用未設置爲對象的實例
每次我打電話CreateOrganizationProfile我得到如下:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Office.Server.UserProfiles.OrganizationProfile.set_Parent(ProfileBase value)
我正在使用的確切的代碼是:
[WebMethod]
public void CreateOrganisation(string OrganisationName)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(_serverName))
{
// Removing this will cause the error "Operation is not valid due to the current state of the object".
HttpContext.Current = null;
SPServiceContext context = SPServiceContext.GetContext(site);
ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
// choose default organization profile subtype as the subtype
string subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.Organization);
ProfileSubtype subType = psm.GetProfileSubtype(subtypeName);
OrganizationProfileManager opm = new OrganizationProfileManager(context);
// choose Root Organization as the parent
OrganizationProfile parentOrg = opm.RootOrganization;
// create an organization profile and set its display name
OrganizationProfile profile = opm.CreateOrganizationProfile(subType, parentOrg);
profile.DisplayName = "Test Org1";
// commit to save changes
profile.Commit();
}
});
return;
}
奇怪的是,別人碰到了確切的問題在這裏http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/7b5101fd-0ea6-4716-82b1-ac4609b9973c/ ,但它從未解決。
我已確認用戶配置文件服務正在運行並進行響應。另外,調用CreateOrganizationProfile時,parentOrg和subtypeName不爲空。
有沒有人有我可以嘗試的東西,或者任何人都可以發現什麼可能是問題?
非常感謝!
有任何更新,我面臨同樣的問題 –