Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

security error in custom workflow

Posted on by 2,397

Hi, I have added System.Web.Extensions to custom workflow, and it gave me this error, any solution to this problem?

Exception Details Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): CRM.Workflows.Email: System.MethodAccessException: Attempt by security transparent method 'CRM.Workflows.Email.ExecuteCRMWorkFlowActivity(System.Activities.CodeActivityContext, LocalWorkflowContext)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed. Assembly 'CRM.Workflows, Version=1.3.0.0, Culture=neutral, PublicKeyToken=dc437796e33d376f' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted. Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.Detail: <OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts"> <ActivityId>d0fd30d7-bf05-4a98-9816-4e44ea2f5095</ActivityId> <ErrorCode>-2147220956</ErrorCode> <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" /> <Message>Unexpected exception from plug-in (Execute): CRM.Workflows.Email: System.MethodAccessException: Attempt by security transparent method 'CRM.Workflows.Email.ExecuteCRMWorkFlowActivity(System.Activities.CodeActivityContext, LocalWorkflowContext)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed. Assembly 'CRM.Workflows, Version=1.3.0.0, Culture=neutral, PublicKeyToken=dc437796e33d376f' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted. Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.</Message> <Timestamp>2017-11-28T20:37:43.253457Z</Timestamp> <ExceptionRetriable>false</ExceptionRetriable> <ExceptionSource>PluginExecution</ExceptionSource> <InnerFault i:nil="true" /> <OriginalException>System.MethodAccessException at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout) at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary`2 inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions) at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, String customActivityTypeName, IExecutionContext requestContext, Dictionary`2 sandboxServices, Boolean useDrawbridgeEnabled, Boolean chaosFailAppDomain) at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, String customActivityTypeName, IExecutionContext requestContext, Dictionary`2 sandboxServices, Boolean useDrawbridgeEnabled, Boolean chaosFailAppDomain) at Microsoft.Crm.Sandbox.SandboxWorker.ExecuteCustomWorkflowActivity(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, SandboxRequestCounter&amp; workerCounter, Boolean returnTraceInfo)</OriginalException> <TraceText> Internal user : 2E1BF026-95AE-E711-A81C-005056B5FEFA,4C42D128-ACAE-E711-A81C-005056B5FEFA Internal List Items : 2E1BF026-95AE-E711-A81C-005056B5FEFA Internal List Items : 4C42D128-ACAE-E711-A81C-005056B5FEFA Internal user: 2E1BF026-95AE-E711-A81C-005056B5FEFA Internal user: 4C42D128-ACAE-E711-A81C-005056B5FEFA finish toParty setup start to setup fromParty system user : c6fd02c2-a6ae-e711-a81c-005056b5fefa From and To parties are set up. {""{template1}"":""car"",""{template2}"":""red""} </TraceText> </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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) 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.Crm.Sandbox.ISandboxHost.ExecuteCustomWorkflowActivityAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String assemblyContents, Boolean returnTraceInfo) at Microsoft.Crm.Sandbox.SandboxCustomActivity.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo) at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context) 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): CRM.Workflows.Email: System.MethodAccessException: Attempt by security transparent method 'CRM.Workflows.Email.ExecuteCRMWorkFlowActivity(System.Activities.CodeActivityContext, LocalWorkflowContext)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.

Assembly 'CRM.Workflows, Version=1.3.0.0, Culture=neutral, PublicKeyToken=dc437796e33d376f' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.

Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.Detail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
 <ActivityId>d0fd30d7-bf05-4a98-9816-4e44ea2f5095</ActivityId>
 <ErrorCode>-2147220956</ErrorCode>
 <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
 <Message>Unexpected exception from plug-in (Execute): CRM.Workflows.Email: System.MethodAccessException: Attempt by security transparent method 'CRM.Workflows.Email.ExecuteCRMWorkFlowActivity(System.Activities.CodeActivityContext, LocalWorkflowContext)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.

Assembly 'CRM.Workflows, Version=1.3.0.0, Culture=neutral, PublicKeyToken=dc437796e33d376f' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.

Assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.Web.Extensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.</Message>


*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: security error in custom workflow

    You should use ILmerge to collect all referenced assemblies into one - nishantrana.me/.../using-ilmerge-for-plugin-in-crm

    Good luck.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: security error in custom workflow

    Seems like you are using an On-Prem environment. Can you add the Newtonsoft.Json to your GAC, and see if that works?

    If that doesn't work, can you test changing your registered workflow from isolated to none.

    I think you might have to change that to get your logic working.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: security error in custom workflow

    Hi, Andrii,

    I'd prefer using newton.json, but I got this error as well

    Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified


  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: security error in custom workflow

    System.Web.Extensions is partially trust assembly for the sandbox. You will not be able to make it work.

    Use Newton.Json or System.Runtime.Serialization.Json.

    Good luck.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: security error in custom workflow

    Hi, it is like this,

     string json =@"{ ""{ template1 }"":""car"",""{ template2} "":""red""}";
                        var serializer = new JavaScriptSerializer();
                        Dictionary<string, string> replacements = serializer.Deserialize<Dictionary<string, string>>(json);


  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: security error in custom workflow

    How about this:

    stackoverflow.com/.../serialize-a-dictionarystring-string-in-specific-format

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: security error in custom workflow

    Can you share your code where you are trying to do this?

    Alex's response is correct. Possibly something has to be modified in your WF code.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: security error in custom workflow

    Thanks, but it doesn't look like it is able to deserialize into dictionary directly.

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: security error in custom workflow

    Hi,

      you'll need to use DataContractJsonSerializer instead:

    www.magnetismsolutions.com/.../how-to-serialize-to-json-in-sandboxed-plugin-for-dynamics-365

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: security error in custom workflow

    So, I am trying to get json format string, and deserialize, it is in sandbox

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans