简体   繁体   English

部署步骤“收回解决方案”中发生错误: <CLASS> 无法反序列化,因为它没有公共默认构造函数

[英]Error occurred in deployment step 'Retract Solution': <CLASS> cannot be deserialized because it does not have a public default constructor

I am using this tutorial as example to create a timer job. 我以本教程为例创建计时器作业。

Here is my timer job code: 这是我的计时器作业代码:

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

namespace CalcAnnualConsumptionTotals
{
    public class GroupAnnualConsumption : SPJobDefinition
    {
        public GroupAnnualConsumption() : base() {} // <-- public default constructor

        public GroupAnnualConsumption(string jobName, SPService service, 
               SPServer server, SPJobLockType lockType)
               : base(jobName, service, server, lockType)
        {
            this.Title = "Group Annual Consumption";
        }

        public GroupAnnualConsumption(string jobName, SPWebApplication webapp)
            : base(jobName, webapp, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "Group Annual Consumption";
        }

        public override void Execute(Guid targetInstanceId)
        {
            .....
        }
    }
}

As you can see I have the default public constructor but when I try to deploy this it shows me error of: 如您所见,我具有默认的公共构造函数,但是当我尝试部署它时,它显示以下错误:

Error occurred in deployment step 'Retract Solution': CalcAnnualConsumptionTotals.GroupAnnualConsumption cannot be deserialized because it does not have a public default constructor 部署步骤“撤回解决方案”中发生错误:CalcAnnualConsumptionTotals.GroupAnnualConsumption无法反序列化,因为它没有公共默认构造函数

When the first time I got this error I had actually forgotten to add default constructor. 当我第一次遇到此错误时,我实际上忘记了添加默认构造函数。 But even after adding it is showing me the error. 但是即使添加了它也会向我显示错误。 I thought that my initial attempt would be partially successfull resulting in deployment. 我认为我的最初尝试会部分成功,从而导致部署。 But I can't find it even via Central Administration or Get-SPTimerJob . 但是,即使通过管理中心或Get-SPTimerJob我也找不到它。

Any ideas why this error is coming up. 任何想法为什么会出现此错误。

Okay, here was the problem. 好的,这就是问题所在。 As I already mentioned in the question 正如我在问题中已经提到的

...When the first time I got this error I had actually forgotten to add default constructor.... ...当我第一次遇到此错误时,我实际上忘记了添加默认构造函数。...

So what happened was that the solution got deployed on SharePoint but the error came at first time also (can't recollect if it was the same error or not). 因此发生的事情是该解决方案已部署到SharePoint上,但该错误也是在第一时间出现的(无论是否是相同的错误,都无法回忆)。 Next time when I rectified the error and tried to deploy, it showed me the error: 下次当我更正错误并尝试部署时,它向我显示了错误:

Error occurred in deployment step ' Retract Solution ': CalcAnnualConsumptionTotals.GroupAnnualConsumption cannot be deserialized because it does not have a public default constructor 部署步骤“撤回解决方案 ”中发生错误:CalcAnnualConsumptionTotals.GroupAnnualConsumption无法反序列化,因为它没有公共默认构造函数

Retract Solution was the keyword here. 收回解决方案是此处的关键字。 When SharePoint tried to deploy updated solution it had to retract the old one but could not and because of error in (old) solution. 当SharePoint尝试部署更新的解决方案时,它不得不撤回旧的解决方案,但是由于(旧)解决方案中的错误而无法撤消。

So I went to Manage Farm Solutions in Central Administration and remove the solution. 因此,我去了管理 中心的“ 管理农场解决方案”并删除了解决方案。 Then when I deployed, it worked. 然后,当我部署时,它起作用了。

The above didn't work for me, but I did find a solution and wanted to post it here in case anyone else runs into the same situation. 上面的方法对我不起作用,但是我确实找到了解决方案,并希望将其发布在这里,以防其他人遇到相同的情况。

In my case, I was not able to uninstall via the Manage Farm Solutions page, at least, not initially. 就我而言,至少在最初无法通过“管理服务器场解决方案”页面进行卸载。

I had to first fix the code by adding a default constructor. 我必须首先通过添加默认构造函数来修复代码。 Then I had to GAC the file using gacutil . 然后,我不得不使用gacutil将文件GAC起来。 I then reset IIS using iisreset /restart . 然后,我使用iisreset / restart重置IIS。 Only then was I able to request that the solution be retracted in the Manage Farm Solutions page. 直到那时,我才能够在“管理农场解决方案”页面中请求撤回解决方案。

Unfortunately, then it just sat there. 不幸的是,它就坐在那儿。 So, to fix that problem I did: 因此,要解决该问题,我做了:

  1. stsadm -o enumdeployments stsadm -o枚举
  2. stsadm -o canceldeployment -id "the guid value displayed in step 1" stsadm -o canceldeployment -id“步骤1中显示的GUID值”
  3. via powershell: remove-spsolution -Identity solutionname.wsp -force 通过Powershell:remove-spsolution -Identity solutionname.wsp -force
  4. iisreset /restart (you may get an error during redeploy that the solution is still installed unless you bounce iis manually) iisreset / restart(重新部署解决方案之前,您可能会收到错误消息,除非您手动弹跳iis,否则仍然可以安装该解决方案)

Then I was able to redeploy and get back to working. 然后,我得以重新部署并重新开始工作。

From here : 这里

You are also required to call either the web service association constructor or the service application association constructor from one of your timer job definition's constructors. 您还需要从您的计时器作业定义的构造函数之一调用Web服务关联构造函数或服务应用程序关联构造函数。 Remember, your timer job must be associated with one of these two entities. 请记住,您的计时器作业必须与这两个实体之一相关联。 The only time that an association can be created is from the constructors on the SPJobDefinition class, so one of your constructors has to be associated with a call down to the appropriate base constructor. 只能从SPJobDefinition类上的构造函数创建关联,因此您的一个构造函数必须与对适当的基本构造函数的调用相关联。

It appears you need to set one of those two properties from your default constructor. 似乎您需要从默认构造函数中设置这两个属性之一。 It would be easiest if you can pass the values to one of your other constructors. 如果可以将值传递给其他构造函数之一,那将是最简单的。

Edit: To clarify, I think passing the jobname parameter to the base constructor would suffice. 编辑:为澄清jobname ,我认为将jobname参数传递给基本构造函数就足够了。 If you don't have access to that value (is it hard-coded, or in a config file?) you may have to re-structure things. 如果您无权访问该值(它是硬编码的,还是在配置文件中?),则可能必须重新组织事物。

That said, I've never worked with Sharepoint, so I could be off base. 就是说,我从未与Sharepoint合作过,所以我可能会不在基地。

It seems the "old version" of SharePoint Job is still up and running. 看来SharePoint Job的“旧版本”仍然可以运行。

When you deploy a SharePoint Job, SharePoint Timer service has to be restarted. 部署SharePoint作业时,必须重新启动SharePoint Timer服务

How to restart SharePoint Timer service via PowerShell 如何通过PowerShell重新启动SharePoint Timer服务

function Restart-SPTimerV4()
{
  [array]$servers= Get-SPServer | ? {$_.Role -eq "Application"}            
  $farm = Get-SPFarm            
  foreach ($server in $servers)            
  {            
     Write-Host "Restarting Timer Job on $server"                                      
     $Service = Get-WmiObject -Computer $server.name Win32_Service -Filter "Name='SPTimerV4'"                        
     if ($Service -ne $null)                         
     {                             
        $Service.InvokeMethod('StopService',$null)            
        Start-Sleep -s 7            
        $service.InvokeMethod('StartService',$null)                             
        Start-Sleep -s 7            
        Write-Host "Timer Job successfully restarted on $server"                        
     }             
     else            
     {            
        write-host -ForegroundColor Yellow "Could not find SharePoint 2010 Timer Service on $server"            
     }            
  }
}

暂无
暂无

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

相关问题 无法反序列化属性,因为成员“属性”不是公共的 - Property cannot be deserialized because the member 'properties' is not public 窗口的默认构造函数是否必须公开? - Does a window's default constructor have to be public? 无法序列化,因为它没有无参数的构造函数 - cannot be serialized because it does not have a parameterless constructor 无法序列化,因为它没有无参数的构造函数 - cannot be serialized because it does not have a parameterless constructor WebAPI和mvc4发生错误类型&#39;.Controllers.APICategoryController&#39;没有默认的构造函数 - WebAPI and mvc4 An error has occurred Type '.Controllers.APICategoryController' does not have a default constructor WCF Singleton-Service错误:提供的服务类型不能作为服务加载,因为它没有默认构造函数 - WCF Singleton-Service error: The service type provided could not be loaded as a service because it does not have a default constructor ASP.NET 核心 - 无法合并“ApplicationDbContext”类型的 DbContext,因为它没有接受单个参数的公共构造函数 - ASP.NET Core- The DbContext of type 'ApplicationDbContext' cannot be pooled because it does not have a public constructor accepting a single parameter 元组无法序列化,因为它没有无参数构造函数 - Tuple cannot be serialized because it does not have a parameterless constructor 无法序列化对象,因为它没有无参数的构造函数 - Object cannot be serialized because it does not have a parameterless constructor Service.datalist无法序列化,因为它没有无参数的构造函数 - Service.datalist cannot be serialized because it does not have a parameterless constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM