SharePoint 2010获取ArgugmentException:在SPPersistedObject上调用Update时,该值不是有效的guid

时间:2010-11-17 15:26:04

标签: c# sharepoint-2010

我有几个派生自SPPersistedObject的类。其中一个是我的顶级类,然后包含其他派生的SPPersistedObjects的集合。以下是我的代码的大致轮廓:

[System.Runtime.InteropServices.GuidAttribute("9BEDC353-F0AC-40FA-A28B-E18FB22EA9CA")
internal class FolderSettings : SPPersistedObject
{
     [Persisted]
     Guid _folderId;

     [Persisted]
     string _folderName;

     public FolderSettings() : base() {}

     protected FolderSettings(Guid folderId, string folderName) : base()
     {
         _folderId = folderId;
         _folderName = folderName;
     }
}

[System.Runtime.InteropServices.GuidAttribute("329DE509-76E6-4FA5-A9C1-2543F0A6B5D3")]
internal class EnhancedFolderSettings : FolderSettings
{
    [Persisted]
    string _outputLocation;

    public EnhancedFolderSettings() : base() {}

    public EnhancedFolderSettings(Guid folderId, string folderName,
        string outputLocation) : base(folderId, folderName)
    {
         _outputLocation = outputLocation;
    }
}

[System.Runtime.InteropServices.GuidAttribute("62FA87FB-2BB4-4AC6-A82A-737E8BEC0219")]
internal class EnhancedFolderSettingsCollection : SPPersistedObject,
    IDictionary<Guid, EnhancedFolderSetrtings>
{
     [Persisted]
     Dictionary<Guid, EnhancedFolderSettings> _collection =
         Dictionary<Guid, EnhancedFolderSettings>();

     public EnhancedFolderSettingsCollection() : base() {}

     // Implementation of IDictionary Interface here

     // Implementation of ICollection Interface here

     // Implementation of IEnumerable Interface here
}

[System.Runtime.InteropServices.GuidAttribute("F080ED50-85DF-4821-884B-97B05995F8F1")]
internal class FeatureSettings : SPPersistedObject
{
     [Persisted]
     string _workingFolder;

     [Persisted]
     string _serviceIpAddress;

     public FeatureSettings() : base() {}

     public FeatureSettings(string name, SPPersistedObject parent)
         : base(name, parent)
     {
     }

     protected override bool HasAdditionalUpdateAccess()
     {
         return true;
     }
}

[System.Runtime.InteropServices.GuidAttribute("C54B006A-69D4-4315-A9FF-F7998A985935")]
internal class EnhancedFeatureSettings : FeatureSettings
{
     const string _SETTINGS_NAME = "EnhancedSettingsName";

     [Persisted]
     Dictionary<Guid, EnhancedFolderSettingsCollection> _siteFeatureSettings;

     public EnhancedFeatureSettings() : base() {}

     public EnhancedFeatureSettings(SPPersistedObject parent)
         : base(_SETTINGS_NAME, parent)
     {
     }

     public static EnhancedFeatureSettings GetSettings(bool createNew)
     {
          EnhancedFeatureSettings settings =
              SPFarm.Local.GetChild<EnhancedFeatureSettings>(_SETTINGS_NAME);
          if (settings == null && createNew)
          {
               settings = new EnhancedFeatureSettings(SPFarm.Local);
          }
          return settings;
     }

     internal EnhancedFolderSettingsCollection GetSiteSettings(Guid siteId)
     {
          EnhancedFolderSettingsCollection collection = null;
          _siteFeatureSettings.TryGetValue(siteId, out collection);
          return collection;
     }

     internal Dictionar<Guid, EnhancedFolderSettingsCollection> FolderSettings
     {
          get
          {
                return _siteFeatureSettings;
          }
     }
}

这就是所有的设置类,现在这里有一些示例代码试图更新设置并导致错误。应该注意,这是在管理上下文中运行的(来自CentralAdmin配置窗口),所以我认为这不是权限相关的:

public void UpdateSettings(Guid siteId, Guid folderId,
     EnhancedFolderSettings currentSettings)
{
      var settings = EnhancedFeatureSettings.GetSettings(true);
      var siteSettings = settings.GetSiteSettings(siteId);
      if (siteSettings == null)
      {
           siteSettings = new EnhancedFolderSettingsCollection();
      }

      siteSettings[folderId] = currentSettings;
      settings.FolderSettings[siteId] = siteSettings;

      settings.Update() // This is the line that is causing the exception
}

任何帮助将不胜感激。例外是:

  

System.ArgumentException:该值不是有效的guid。

堆栈跟踪指向settings.Update()行。

3 个答案:

答案 0 :(得分:1)

目前情况下可接受的解决方案是改变现场实施。您可以使用数组创建自己的类,派生自SPAutoSerializingObject,IEnumerable等,您可以在其中实现Dictionary(或List)字段的所有功能,并使用此类 Dictionary&lt;&gt ; 列表&lt;&gt;

希望它有所帮助。

答案 1 :(得分:0)

我正在回答我自己的问题,因为我还没有答案,现在收到了新的信息。您可以在SharePoint.SE上看到我发布的相关问题。我发现这段代码中有一些缺失的部分,但即使在处理了一些这些事情后我仍然遇到问题。在试图雇用一名顾问来帮助解决这个问题之后,我收到了一个基本上说“不要那样做”的回复。 SPPersistedObject框架可能是片状的(在互联网上有几个关于此的帖子),并不是真正的设计来做我想做的事情。建议重新设计设置框架以使用隐藏列表。

答案 2 :(得分:0)

我有同样的问题,我试图在SPPersistedObject中找到更深入的解决方案。在我的研究期间,我删除了类属性中的guid,并在该应用程序之后抛出一个新的异常。 “INSERT语句与FOREIGN KEY约束”FK_Dependencies1_Objects“冲突。冲突发生在数据库”SharePoint_Config“,表”dbo.Objects“,列”Id“中。 该声明已被终止。“因此,此异常来自SharePoint Config数据库。