簡體   English   中英

安裝計時器作業時發生意外的異常-無法從程序集中創建接收器對象

[英]Unexpected exception when installing timer job - Failed to create receiver object from assembly

激活功能時出現以下錯誤,該功能應該安裝計時器作業。

無法從程序集“ MundoNetElements,版本= 1.0.0.0,文化=中性,PublicKeyToken = 9922d1e7c40d98f8”,類“ MundoNetElements.Features.NotificacionesContratosJob.NotificacionesContratosJobEventReceiver”中為功能部件“ MundoNetElements_ID775a-7(808:33-87:87:87-47 -518bcdaceb06)。: System.ArgumentNullException:值不能為null。 參數名稱:System.Activator.CreateInstance處的類型(Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()處的類型(類型,布爾值非公共)

這是我的代碼,沒有什么特別的,並使用了其他網站的一些示例代碼。

。特征

<?xml version="1.0" encoding="utf-8"?>
<feature xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="e67975ff-4d4f-4f6a-9349-e46cc0398745" alwaysForceInstall="true" description="This job executes periodically the notification process and the cleaning for the Mundo Net application" featureId="e67975ff-4d4f-4f6a-9349-e46cc0398745" imageUrl="" receiverAssembly="$SharePoint.Project.AssemblyFullName$" receiverClass="$SharePoint.Type.5de345c1-6a4c-48d8-8a8f-f80c531b438a.FullName$" scope="Site" solutionId="00000000-0000-0000-0000-000000000000" title="MundoNetJob" version="" deploymentPath="$SharePoint.Project.FileNameWithoutExtension$_$SharePoint.Feature.FileNameWithoutExtension$" xmlns="http://schemas.microsoft.com/VisualStudio/2008/SharePointTools/FeatureModel" />

TEMPLATE.XML

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>

事件接收者

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Security;

namespace MundoNetElements.Features.MundoNetJob
{
    /// <summary>
    /// Esta clase controla los eventos generados durante la activación, desactivación, instalación, desinstalación y actualización de características.
    /// </summary>
    /// <remarks>
    /// El GUID asociado a esta clase se puede usar durante el empaquetado y no se debe modificar.
    /// </remarks>

    [Guid("5de345c1-6a4c-48d8-8a8f-f80c531b438a")]
    public class MundoNetJobEventReceiver : SPFeatureReceiver
    {
        const string List_JOB_NAME = "MundoNetJob";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == List_JOB_NAME)
                    job.Delete();
            }

            // install the job
            MundoNetElements.MundoNetJob listLoggerJob = new MundoNetElements.MundoNetJob(List_JOB_NAME, site.WebApplication);
            SPDailySchedule schedule = new SPDailySchedule();
            schedule.BeginHour = 23;
            schedule.BeginMinute = 0;
            schedule.BeginSecond = 0;                        
            schedule.EndHour = 23;
            schedule.EndMinute = 15;
            schedule.EndSecond = 0;
            listLoggerJob.Schedule = schedule;
            listLoggerJob.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == List_JOB_NAME)
                    job.Delete();
            }
        }
    }
}

和計時器工作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace MundoNetElements
{
    public class MundoNetJob : SPJobDefinition
    {
        public MundoNetJob() : base()
        {

        }

        public MundoNetJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType)
        {

        }

        public MundoNetJob(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        { 
            this.Title = "Mundo Net job"; 
        }

        public override void Execute(Guid contentDbId)
        {
            // get a reference to the current site collection's content database

            //SPWebApplication webApplication = this.Parent as SPWebApplication;

            //SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

            //// get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database

            //SPList Listjob = contentDb.Sites[0].RootWeb.Lists["ListTimerJob"];

            //// create a new list Item, set the Title to the current day/time, and update the item

            //SPListItem newList = Listjob.Items.Add();

            //newList["Title"] = DateTime.Now.ToString();

            //newList.Update();

        }
    }
}

您是否已重命名名稱空間? SharePoint試圖在名稱空間MundoNetElements.Features.NotificacionesContratosJob中創建一個對象。 您包含的事件接收器具有名稱空間MundoNetElements.Features.MundoNetJob

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM