using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace test
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//is ok
var str2 = JsonConvert.SerializeObject(new test002 { ID = 1 });
Response.Write(str2);
//local is OK, Server has error:
//Unable to obtain public key for StrongNameKeyPair
var str1 = JsonConvert.SerializeObject(new test001 { ID = 1 });
Response.Write(str1);
}
}
[DataContract]
public class test001Metadata { }
[DataContract(IsReference = true)]
[MetadataType(typeof(test001Metadata))]
[Serializable]
public partial class test001
{
[DataMember]
public long ID { get; set; }
}
[DataContract(IsReference = true)]
[Serializable]
public partial class test002
{
[DataMember]
public long ID { get; set; }
}
}
Details:
[ArgumentException: Unable to obtain public key for StrongNameKeyPair.]
System.Reflection.StrongNameKeyPair.ComputePublicKey() +201
System.Reflection.StrongNameKeyPair.get_PublicKey() +20
System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable
1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) +9692129
System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) +125
System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable
1 assemblyAttributes, SecurityContextSource securityContextSource) +43
System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) +42
Newtonsoft.Json.Utilities.DynamicWrapper.Init() in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\DynamicWrapper.cs:47
Newtonsoft.Json.Utilities.DynamicWrapper.GenerateWrapperType(Type interfaceType, Type underlyingType) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\DynamicWrapper.cs:105
Newtonsoft.Json.Utilities.DynamicWrapper.GetWrapper(Type interfaceType, Type realObjectType) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\DynamicWrapper.cs:85
Newtonsoft.Json.Utilities.DynamicWrapper.CreateWrapper(Object realObject) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\DynamicWrapper.cs:123
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAssociateMetadataTypeFromAttribute(Type type) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonTypeReflector.cs:258
Newtonsoft.Json.Utilities.ThreadSafeStore2.AddValue(TKey key) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\ThreadSafeStore.cs:38
Newtonsoft.Json.Utilities.ThreadSafeStore
2.Get(TKey key) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\ThreadSafeStore.cs:31
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute(Type type) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonTypeReflector.cs:288
Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute(ICustomAttributeProvider attributeProvider) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonTypeReflector.cs:363
Newtonsoft.Json.Utilities.ThreadSafeStore2.AddValue(TKey key) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\ThreadSafeStore.cs:38
Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\ThreadSafeStore.cs:31
Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:725
Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:228
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:77
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:58
Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:569
Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:749
Newtonsoft.Json.JsonConvert.SerializeObject(Object value) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\JsonConvert.cs:672
test.WebForm1.Page_Load(Object sender, EventArgs e) in d:\personal\documents\visual studio 2010\Projects\test\test\WebForm1.aspx.cs:19
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207