c# - 安装计时器作业时出现意外异常 - 无法从程序集创建接收器对象

标签 c# sharepoint sharepoint-2010 timer-jobs

激活功能时出现以下错误,此功能应该安装计时器作业。

Failed to create receiver object from assembly "MundoNetElements, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9922d1e7c40d98f8", class "MundoNetElements.Features.NotificacionesContratosJob.NotificacionesContratosJobEventReceiver" for feature "MundoNetElements_NotificacionesContratosJob" (ID: 33578802-a775-4777-9317-518bcdaceb06).: System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, Boolean nonPublic) at 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" />

模板.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 中创建一个对象。 您包含的事件接收器具有 namespace MundoNetElements.Features.MundoNetJob

希望这对您有所帮助。

关于c# - 安装计时器作业时出现意外异常 - 无法从程序集创建接收器对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32107418/

相关文章:

c# - 如何构建可编译为 Func<T> 的表达式?

c# - 将 XML WebResponse 转换为通用对象

c# - 在洋葱架构中,我在哪里保存文件上传和计算的逻辑?

sql - 在 SharePoint 2010 中指定不同的数据库服务器

javascript - 自定义 sharepoint 2010 xslt 列表 - 通过 javascript 编辑项目 - 编辑后数据未刷新

c# - 以大写形式显示句子中的最后一个单词

powershell - 解释 Powershell [void] 行为

sharepoint - 如何为 SharePoint 事件接​​收器设置过滤器?

html - html 中的高度百分比

c# - 如何在 Sharepoint Web 部件中将 excel 文件(xlsx 文件)转换为 pdf?