1

Closed

Unable to obtain public key for StrongNameKeyPair

description

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, IEnumerable1 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, IEnumerable
1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource) +125
System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable1 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.ThreadSafeStore
2.AddValue(TKey key) in c:\Dev\Releases\Working\Newtonsoft.Json\Src\Newtonsoft.Json\Utilities\ThreadSafeStore.cs:38
Newtonsoft.Json.Utilities.ThreadSafeStore2.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.ThreadSafeStore
2.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

file attachments

Closed May 4, 2012 at 11:58 AM by JamesNK
This is a problem with your computer. Maybe this will help? http://stackoverflow.com/questions/5659740/unable-to-obtain-public-key-for-strongnamekeypair

comments

yongfa365 wrote May 4, 2012 at 5:17 AM

files are attached

yongfa365 wrote May 4, 2012 at 5:20 AM

Server is windows 2008 r2 X64
Windows is up to date
json.net all version

klogan wrote Jun 11, 2012 at 7:52 PM

Can you expand on how this was fixed or what causes this issue? I just ran into the same issue and can't replicate it locally. It works locally, but not on our test server.

I'm using 4.5.5.

Thanks.