none
sharepoint 2010 事件接收器出错,怎么办 RRS feed

  • 问题

  • 我在做sharepoint 2010事件接收器时,我首先创建事件接收器模板,代码如下:

    Elements.xml代码:<?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Receivers ListTemplateId="10001" RootWebOnly="True"  Scope="Web">
          <Receiver>
            <Name>EventReceiver1ItemAdded</Name>
            <Type>ItemAdded</Type>
            <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
            <Class>EventReceiverList.EventReceiver1.EventReceiver1</Class>
            <SequenceNumber>10000</SequenceNumber>
          </Receiver>

    </Receivers>
    </Elements>

    cs代码:

     public override void ItemAdded(SPItemEventProperties properties)
            {
                properties.Status = SPEventReceiverStatus.CancelWithError;
                properties.Cancel = true;
            
              

               SPSite site = new SPSite(properties.SiteId);
               SPWeb web = site.OpenWeb(properties.RelativeWebUrl);
               UserInfo userInfo = new UserInfo();
               string loginName = properties.UserLoginName;
               LogInfo logInfo = Common.GetLogInfo(loginName);
               //logInfo. = properties.ReceiverData;
              
               //SPListItem item=
               userInfo.model = "知识管理";
               userInfo.UI = "知识库";

               userInfo.loginInfo  = "操作" + userInfo.model + "添加" + userInfo.UI + " " + logInfo.UserName + "操作成功";
               logInfo.UI = userInfo.UI;//界面
               logInfo.Module = userInfo.model;//模块
               logInfo.Infomation = userInfo.loginInfo;

               Common.WriteLog(logInfo);

           }

    但是问题是当我在自定义列表添加一项时,出现异常,

    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.Runtime.InteropServices.COMException: <nativehr>0x81020089</nativehr><nativestack></nativestack>从沙盒代码程序集中激活类型时出错。未能找到缓存沙盒程序集。

    源错误:

    执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

    堆栈跟踪:

    [COMException (0x81020089): <nativehr>0x81020089</nativehr><nativestack></nativestack>从沙盒代码程序集中激活类型时出错。未能找到缓存沙盒程序集。]
      Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback) +0
      Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback) +406
    
    [SPException: 从沙盒代码程序集中激活类型时出错。未能找到缓存沙盒程序集。]
      Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) +27387298
      Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback) +27774399
      Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents, String filename) +26514477
      Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents, String filename) +26511086
      Microsoft.SharePoint.SPListItem.Update() +161
      Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +848
      Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +1167
    

    “/”应用程序中的服务器错误。

    <nativehr>0x81020089</nativehr><nativestack></nativestack>从沙盒代码程序集中激活类型时出错。未能找到缓存沙盒程序集。

     

    高手赐教,感激涕零
    2011年7月20日 7:56

答案

  • 看这个错误提示应该是部署有问题,用VS重新部署试一下

     

    另外,代码里面有一些问题,沙盒解决方案中是不支持 new SPSite("") 的

    2011年7月23日 5:29