简体   繁体   English

安装计时器作业时发生意外的异常-无法从程序集中创建接收器对象

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

I have the following error when activating a feature, this feature is supposed to install a timer job. 激活功能时出现以下错误,该功能应该安装计时器作业。

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. 无法从程序集“ MundoNetElements,版本= 1.0.0.0,文化=中性,PublicKeyToken = 9922d1e7c40d98f8”,类“ MundoNetElements.Features.NotificacionesContratosJob.NotificacionesContratosJobEventReceiver”中为功能部件“ MundoNetElements_ID775a-7(808:33-87:87:87-47 -518bcdaceb06)。: System.ArgumentNullException:值不能为null。 Parameter name: type at System.Activator.CreateInstance(Type type, Boolean nonPublic) at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() 参数名称:System.Activator.CreateInstance处的类型(Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()处的类型(类型,布尔值非公共)

This is my code,which doesnt have anything special and used several sample codes from other websites. 这是我的代码,没有什么特别的,并使用了其他网站的一些示例代码。

.feature 。特征

<?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 TEMPLATE.XML

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

Event Receiver 事件接收者

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();
            }
        }
    }
}

And the timer job 和计时器工作

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();

        }
    }
}

Have you renamed your namespace? 您是否已重命名名称空间? SharePoint is trying to create an object in namespace MundoNetElements.Features.NotificacionesContratosJob. SharePoint试图在名称空间MundoNetElements.Features.NotificacionesContratosJob中创建一个对象。 The event receiver you've included has namespace MundoNetElements.Features.MundoNetJob 您包含的事件接收器具有名称空间MundoNetElements.Features.MundoNetJob

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将程序集安装到SQL Server中时如何解决失败的程序集验证 - How to resolve failed assembly verification when installing assembly into SQL Server 从激活的程序集(插件)加载时,System.Windows.Forms.Timer对象不会打勾 - System.Windows.Forms.Timer object does not tick when loaded from an activated assembly (plugin) 如何为计时器作业创建可视化 - How to create a visualization for a timer job 使用AppDomain从程序集创建对象实例 - Create object instance from assembly using AppDomain 通过卫星组件的反射创建 object - Create an object via reflection from a satellite assembly 删除计时器作业时,它将引发错误“对象引用未设置为对象的实例” - When deleting timer job it throws error 'Object reference not set to an instance of an object' Twitterizer引发异常:反序列化对象时发生意外的令牌:整数 - Twitterizer throwing an exception: Unexpected token when deserializing object: Integer 在经过的事件中,计时器是否会创建新的 object? - Does the timer create new object when in the elapsed event? 指定程序集创建对象 - Specifying an Assembly to Create an Object 使用MEF时从另一个程序集导入会引发异常 - Import from another assembly throws exception when using MEF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM