SharePoint部件2中的HRESULT异常:0x80020009(DISP_E_EXCEPTION))

时间:2010-04-17 08:47:44

标签: sharepoint sharepoint-2007

在我之前发布的this post之后,每次尝试重新连接2个网址时,我都会收到同样的错误。

基本上,这是代码。它在LongRunningOperationJob中运行:

SPWeb existingWeb = null;
using (existingWeb = site.OpenWeb(wedId))
{
    SPWeb destinationWeb = createNewSite(existingWeb);
    existingWeb.AllowUnsafeUpdates = true;
    existingWeb.Name = existingWeb.Name + "_old";
    existingWeb.Title = existingWeb.Title + "_old";
    existingWeb.Description = existingWeb.Description + "_old";

    existingWeb.Update()
    existingWeb.AllowUnsafeUpdates = false;

    destinationWeb.AllowUnsafeUpdates = true;
    destinationWeb.Name = existingWeb.Name;
    destinationWeb.Title = existingWeb.Title;
    destinationWeb.Description = existingWeb.Description;

    destinationWeb.Update();
    destinationWeb.AllowUnsafeUpdates = false;

    // null this for what its worth
    existingWeb = null;
    destinationWeb = null;
} // <---- Exception raised here

基本上,代码尝试将现有网站的网址重命名为其他网址,并让目标网址的网址指向旧网站的网址。

当我第一次运行时,我收到了主题中提到的异常。

但是,每次运行之后,我都不会再看到异常了。

网络会被重新布线......但代价是应用程序死于不必要的可怕死亡。

我完全迷失了什么,需要紧急帮助。 sharepoint是否保留了我隐藏的表格,或者上面的逻辑是否存在致命问题?

感谢。

3 个答案:

答案 0 :(得分:1)

最后,我用try catch finally块替换了using块,并最终取消了引用。这个例外从未让我再次困扰过。

感谢。

答案 1 :(得分:0)

我疯狂的猜测是,因为你将destinationWeb设置为null,所以在使用块的末尾它会尝试处理一个不在那里的对象并且会爆炸。删除该语句并尝试。

答案 2 :(得分:0)

这可能与您的错误无关,但我在此代码中看到了两件事:

  1. 目标网络未被处置
  2. 根据声明顺序,我希望这两个网站最终都以“_old”为后缀
  3. 我会用这种方式重写代码:

    SPWeb existingWeb = null; 
    using (existingWeb = site.OpenWeb(wedId)) 
    { 
        using (SPWeb destinationWeb = createNewSite(existingWeb))
        {
            destinationWeb.AllowUnsafeUpdates = true; 
            destinationWeb.Name = existingWeb.Name; 
            destinationWeb.Title = existingWeb.Title; 
            destinationWeb.Description = existingWeb.Description; 
    
            existingWeb.AllowUnsafeUpdates = true; 
            existingWeb.Name += "_old"; 
            existingWeb.Title += "_old"; 
            existingWeb.Description += "_old"; 
    
            existingWeb.Update() 
            existingWeb.AllowUnsafeUpdates = false; 
    
            destinationWeb.Update(); 
            destinationWeb.AllowUnsafeUpdates = false; 
        }
    }