简体   繁体   中英

Register custom workflow activity in Dynamics CRM 2013

I have built a Custom Workflow Activity in Visual Studio 2010 to use in Dynamics CRM 2013 On-Premises and I am trying to register the assembly containing the custom workflow using Plugin Registration Tool with configuration: Sandbox and Database . I have spent hours struggling with the following exception:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Exception retrieving custom activity info - Inheritance security rules violated by type: 'TrmIntergration.Workflow.BaseCodeActivity'. Derived types must either match the security accessibility of the base type or be less accessible.
Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <ErrorCode>-2147200995</ErrorCode>
  <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
  <Message>Exception retrieving custom activity info - Inheritance security rules violated by type: 'TrmIntergration.Workflow.BaseCodeActivity'. Derived types must either match the security accessibility of the base type or be less accessible.</Message>
  <Timestamp>2014-07-31T09:58:46.057735Z</Timestamp>
  <InnerFault>
    <ErrorCode>-2147200995</ErrorCode>
    <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
    <Message>Exception retrieving custom activity info - Inheritance security rules violated by type: 'TrmIntergration.Workflow.BaseCodeActivity'. Derived types must either match the security accessibility of the base type or be less accessible.</Message>
    <Timestamp>2014-07-31T09:58:46.057735Z</Timestamp>
    <InnerFault i:nil="true" />
    <TraceText i:nil="true" />
  </InnerFault>
  <TraceText i:nil="true" />
</OrganizationServiceFault>

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Xrm.Sdk.IOrganizationService.Create(Entity entity)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.CreateCore(Entity entity)
   at Microsoft.Crm.Tools.Libraries.RegistrationHelper.RegisterPlugin(CrmOrganization org, CrmPlugin plugin)
   at Microsoft.Crm.Tools.AssemblyRegistration.PluginRegistrationViewModel.btnregisterClick()

Here is the Activity code:

using System;
using System.Activities;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;

namespace TrmIntergration.Workflow
{
    public sealed class BaseCodeActivity: CodeActivity
    {        
        [Output("Initiating User")]
        [ReferenceTarget("systemuser")]
        public OutArgument<EntityReference> InitiatingUserReference { get; set; }
        protected override void Execute(CodeActivityContext executionContext)
        {
            IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
            InitiatingUserReference.Set(executionContext, new EntityReference("systemuser", workflowContext.InitiatingUserId));
        }
    }
}

Please check this blog . Looks like the same issue.

The reason is that some legacy external libraries don't follow .NET 4.0 security rules. The solution it actually quite simple – revert back to .NET 2.0 security. Simply add the following attribute anywhere inside you're code (after the using statements):

[assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]

您必须包括system.servicemodel命名空间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM