locked
Using System.Web.Extensions in Crm plugin

    Question

  • Hi 

    i am trying to use  System.Web.Script.Serialization.JavaScriptSerializer in CRM plugin. But i get following exception. any ideas how it can be fixed?

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



    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="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220956</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Unexpected exception from plug-in (Execute): TestingSeam.CrmTesting: System.MethodAccessException: Attempt by security transparent method 'TestingSeam.CrmTesting.Execute(System.IServiceProvider)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.


    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>2012-03-30T00:28:19.5193117Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>


    [TestingSeam: TestingSeam.CrmTesting]
    [450a4a06-5078-e111-acd5-1cc1dee8daa5: TestingSeam.CrmTesting: Update of contact]


    FollowupPlugin: System.MethodAccessException: Attempt by security transparent method 'TestingSeam.CrmTesting.Execute(System.IServiceProvider)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.


    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.
       at TestingSeam.CrmTesting.Execute(IServiceProvider serviceProvider)System.Collections.ListDictionaryInternal   at TestingSeam.CrmTesting.Execute(IServiceProvider serviceProvider)Attempt by security transparent method 'TestingSeam.CrmTesting.Execute(System.IServiceProvider)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.


    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.




    </TraceText>
    </OrganizationServiceFault>


    navighag

    Friday, March 30, 2012 3:59 PM

Answers

  • I would recommend against using ILMerge for a core .NET assembly, as it is not supported and there is no real way to know how it will behave. The error message calls out why this can't be used:

    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, ...' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.Detail

    System.MethodAccessException: Attempt by security transparent method 'TestingSeam.CrmTesting.Execute(System.IServiceProvider)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.

    This assembly is marked as conditionally APTCA (allow partially trusted callers attribute), which means that code running in the Sandbox won't be able to call into it without product changes to CRM. Without this change, there isn't a supported workaround.

    Michael

    Thursday, April 12, 2012 10:42 PM

All replies

  • I see references to the partial trust environment.  Are you registering your plugin in the SandBox?  If so, do you have the option of registering it outside the SandBox?
    Friday, March 30, 2012 6:33 PM
  • yes plugin is registered in sandbox environment. I cannot register it outside sandbox.

    navighag

    Friday, March 30, 2012 6:42 PM
  • Well, you could try merging your assembly with the System.Web.Extensions assembly using ILMerge then registering the entire thing.  However if that assembly attempts to access anything outside of the partial trust environment of the Sandbox (which is highly likely) you'll once-again be out of luck.  You'll have to find a JSON serializer that operates in a partial trust environment or roll your own.
    Friday, March 30, 2012 7:10 PM
  • I would recommend against using ILMerge for a core .NET assembly, as it is not supported and there is no real way to know how it will behave. The error message calls out why this can't be used:

    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, ...' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.Detail

    System.MethodAccessException: Attempt by security transparent method 'TestingSeam.CrmTesting.Execute(System.IServiceProvider)' to access security critical method 'System.Web.Script.Serialization.JavaScriptSerializer..ctor()' failed.

    This assembly is marked as conditionally APTCA (allow partially trusted callers attribute), which means that code running in the Sandbox won't be able to call into it without product changes to CRM. Without this change, there isn't a supported workaround.

    Michael

    Thursday, April 12, 2012 10:42 PM