Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Issue with plugin after upgrade to CRM 2016

$
0
0

Hi,

we recently upgraded from CRM 2015 to CRM 2016 on premise and one plugin, which was working fine in CRM 2015, is no longer working in CRM 2016.

I already changed the SDK dlls in the references of the plugin from the 2015 ones to the new 2016 dlls and updated the plugin assembly, but still it doesn't work.

It always throws the error:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=xxx]]: Unexpected exception from plug-in (Execute): CrmVSSolution1.Plugins.PostZuwendungCreate: System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220956</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
  <Message>Unexpected exception from plug-in (Execute): CrmVSSolution1.Plugins.PostZuwendungCreate: System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.</Message>
  <Timestamp>2016-12-16T21:52:21.7150974Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

Any idea, what could be wrong?

thx in advance Thomas

This is the source code of the plugin:

// <copyright file="PostZuwendungCreate.cs" company="">

// Copyright (c) 2016 All Rights Reserved

// </copyright>

// <author></author>

// <date>12/15/2016 1:32:49 PM</date>

// <summary>Implements the PostZuwendungCreate Plugin.</summary>

// <auto-generated>

// This code was generated by a tool.

// Runtime Version:4.0.30319.1

// </auto-generated>

namespace CrmVSSolution1.Plugins

{

using System;

using System.ServiceModel;

using Microsoft.Xrm.Sdk;

using Microsoft.Crm.Sdk.Messages;

///<summary>

/// PostZuwendungCreate Plugin.

///</summary>

publicclassPostZuwendungCreate: Plugin

{

///<summary>

/// Alias of the image registered for the snapshot of the

/// primary entity's attributes after the core platform operation executes.

/// The image contains the following attributes:

/// pb_anzahl_tickets,pb_geschenk,pb_art_geschenk,pb_status_tickets,statuscode

///

/// Note: Only synchronous post-event and asynchronous registered plug-ins

/// have PostEntityImages populated.

///</summary>

privatereadonlystring postImageAlias = "PostImage";

///<summary>

/// Initializes a new instance of the <see cref="PostZuwendungCreate"/> class.

///</summary>

public PostZuwendungCreate()

: base(typeof(PostZuwendungCreate))

{

base.RegisteredEvents.Add(newTuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "fax", newAction<LocalPluginContext>(ExecutePostZuwendungCreate)));

base.RegisteredEvents.Add(newTuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "fax", newAction<LocalPluginContext>(ExecutePostZuwendungCreate)));

// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.

// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.

}

///<summary>

/// Executes the plug-in.

///</summary>

///<param name="localContext">The <see cref="LocalPluginContext"/> which contains the

///<see cref="IPluginExecutionContext"/>,

///<see cref="IOrganizationService"/>

/// and <see cref="ITracingService"/>

///</param>

///<remarks>

/// For improved performance, Microsoft Dynamics CRM caches plug-in instances.

/// The plug-in's Execute method should be written to be stateless as the constructor

/// is not called for every invocation of the plug-in. Also, multiple system threads

/// could execute the plug-in at the same time. All per invocation state information

/// is stored in the context. This means that you should not use global variables in plug-ins.

///</remarks>

protectedvoid ExecutePostZuwendungCreate(LocalPluginContext localContext)

{

if (localContext == null)

{

thrownewArgumentNullException("localContext");

}

IPluginExecutionContext context = localContext.PluginExecutionContext;

IOrganizationService service = localContext.OrganizationService;

ITracingService trace = localContext.TracingService;

// Image für Update Step

Entity postImageEntity = (context.PostEntityImages != null&& context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;

// TODO: Implement your custom Plug-in business logic.

try

{

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] isEntity)

{

Entity entity = (Entity)context.InputParameters["Target"];

// Verify that the target entity represents a fax.

// If not, this plug-in was not registered correctly.

if (entity.LogicalName == "fax")

{

if (context.MessageName == "Create")

{

// Check ob Zuwendungs-Art gleich Ticket ist

int value = ((OptionSetValue)entity.Attributes["pb_art_geschenk"]).Value;

if (value == 108560002)

{

// Feld Zuwendung

EntityReference pbgeschenk = (EntityReference)entity.Attributes["pb_geschenk"];

Entity geschenk = service.Retrieve(pbgeschenk.LogicalName, pbgeschenk.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

CalculateRollupFieldRequest rollupRequest=

newCalculateRollupFieldRequest {Target = newEntityReference(geschenk.LogicalName, geschenk.Id), FieldName = "pb_anzahl_tickets"};

CalculateRollupFieldResponse response =(CalculateRollupFieldResponse)service.Execute(rollupRequest);

geschenk = response.Entity;

service.Update(geschenk);

}

}

if (context.MessageName == "Update")

{

// Check ob Zuwendungs-Art gleich Ticket ist

int uvalue = ((OptionSetValue)postImageEntity.Attributes["pb_art_geschenk"]).Value;

if (uvalue == 108560002)

{

// Feld Zuwendung

EntityReference upbgeschenk = (EntityReference)postImageEntity.Attributes["pb_geschenk"];

Entity ugeschenk = service.Retrieve(upbgeschenk.LogicalName, upbgeschenk.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

CalculateRollupFieldRequest rollupRequest =

newCalculateRollupFieldRequest { Target = newEntityReference(ugeschenk.LogicalName, ugeschenk.Id), FieldName = "pb_anzahl_tickets" };

CalculateRollupFieldResponse response = (CalculateRollupFieldResponse)service.Execute(rollupRequest);

ugeschenk = response.Entity;

service.Update(ugeschenk);

}

}

}

}

}

catch (FaultException<OrganizationServiceFault> ex)

{

thrownewInvalidPluginExecutionException("An error occurred in Tickets plugin", ex);

}

// END TODO

}

}

}


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>