Search This Blog

Tuesday, March 5, 2019

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

While using JavaScriptSerializer class (referencing System.Web.Extension dll in the plugin project) the below error thrown at the run time.

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

Solution:


  JavaScriptSerializer jss = new JavaScriptSerializer();  
           dynamic obj = jss.Deserialize<dynamic>(responsebody);  
           string token = obj["access_token"];  

 Instead of Above Code:
 public class AccessToken
    {
        public string access_token { get; set; }
    } 
using (var memorystream = new MemoryStream())  
           {  
             var deserializer = new DataContractJsonSerializer(typeof(AccessToken));  
             StreamWriter writer = new StreamWriter(memorystream);  
             writer.Write(responsebody);  
             writer.Flush();  
             memorystream.Position = 0;  
             AccessToken deserializedResult = (AccessToken)deserializer.ReadObject(memorystream);  
             string token1 = deserializedResult.access_token;  
           }