I am trying to use the JavaScriptSerializer class in an event receiver which is part of a sandbox solution. When trying to use the class, I get a System.MethodAccessException with the following message:

Assembly 'MyProjectAssembly, Version=, Culture=neutral, PublicKeyToken=b4bce33dbc53d2b3' 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=, 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=[something long]' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.

So, I get that my assembly is partially trusted because it's a sandbox solution. That's fine. But how do I add the System.Web.Extensions assembly to the "PartialTrustVisibleAssemblies" so I can then use it? Is that something I can do in the VS solution package somewhere?

And if not, what are my options here?

  • Did you ever figure this out? I have the same issue. Commented Aug 25, 2016 at 15:34
  • 1
    @MichaelBlackburn I posted an answer with my workaround. Commented Aug 25, 2016 at 15:42

1 Answer 1


The way I worked around this was to abandon using the Microsoft JavaScriptSerializer class, and instead use the Json.NET open source library. You can add it to your VS project using NuGet package manager, and you have to be sure to include the Json.NET .dll in your solution so the .dll will get deployed to SharePoint.

But it will allow you to access that library with the same level of trust as your own code, so it works as a sandbox solution.

  • huh, I was using JavaScriptSerializer specifically because on my dev machine, the event receiver wouldn't even fire when referencing Json.NET unless I added it to my GAC. Commented Aug 25, 2016 at 16:09
  • @MichaelBlackburn I just double checked... After you add Json.NET to your project with NuGet, it ends up in a packages directory in your solution directory. When referencing it in the project references, I browsed to where the .dll is in that folder. Then in the Package, I went to the Advanced tab and added an "additional assembly", again browsing to that same .dll in that same packages folder. Now, in the Additional Assemblies listing it does say deployment target GAC, but the solution is definitely a sandbox solution, and I got it to all work... Commented Aug 25, 2016 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.