代码之家  ›  专栏  ›  技术社区  ›  pstrjds

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

  •  1
  • pstrjds  · 技术社区  · 14 年前

    我有几个从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 回复  |  直到 12 年前
        1
  •  1
  •   VeryWell    13 年前

    在当前形势下,可接受的解决方案是改变现场实施方式。你可以用 阵列 ,派生自spautoserializengobject、IEnumerable等,在这里实现Dictionary(或List)字段的所有功能并使用此类 词典<> 列表<>

    希望能有所帮助。

        2
  •  0
  •   VeryWell    13 年前

    我也有同样的问题,我试图在SPPersistedObject中找到更深层次的解决方案。在我的研究中,我删除了类属性中的guid,然后应用程序抛出一个新的异常。 INSERT语句与外键约束“FK_Dependencies1_Objects”冲突。数据库“SharePoint_Config”、表“dbo.Objects”、列“Id”中发生冲突。 语句已终止。“因此,此异常来自SharePoint配置数据库。

        3
  •  0
  •   Community Nick Dandoulakis    7 年前

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