简体   繁体   English

在Dynamics CRM 2013中注册自定义工作流活动

[英]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 . 我已经在Visual Studio 2010中构建了一个自定义工作流活动 ,以在Dynamics CRM 2013本地中使用,并且我尝试使用具有以下配置的插件注册工具来注册包含自定义工作流的程序集: SandboxDatabase 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. 原因是某些旧版外部库不遵循.NET 4.0安全规则。 The solution it actually quite simple – revert back to .NET 2.0 security. 该解决方案实际上非常简单–恢复为.NET 2.0安全性。 Simply add the following attribute anywhere inside you're code (after the using statements): 只需在代码内的任何位置(在using语句之后)添加以下属性:

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

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

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

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