我有一个工作流服务。我还在该服务中使用了工作流持久性。但是在 IIS 中部署工作流后,我从客户端向服务器上的日志文件中的工作流服务发出请求。我看到一条消息
The execution of the InstancePersistenceCommand named {urn:schemas-microsoft-com:System.Activities.Persistence/command}SaveWorkflow was interrupted by an error.InnerException Message: Type 'System.ServiceModel.Channels.ReceivedFault' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.
Run Code Online (Sandbox Code Playgroud)
我尝试了有关此异常的研究,但没有发现任何内容。
如何解决这个问题?或者让我知道上述异常的原因是什么?
我有2种方法
public static string SerializeObject<T>(T value)
{
if (value == null)
{
return null;
}
var dictionaryObject = new Dictionary<string, object> { { typeof(T).Name, value } };
var jsonString = JsonConvert.SerializeObject(dictionaryObject);
return jsonString;
}
Run Code Online (Sandbox Code Playgroud)
和
public static T DeserializeObject<T>(string jsonString)
{
var objectValue = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
return JsonConvert.DeserializeObject<T>(objectValue.Values.First().ToString());
}
Run Code Online (Sandbox Code Playgroud)
当我用类型反序列化json字符串时
ConcurrentDictionary<KeyValuePair<long, long>, IList<string>>
Run Code Online (Sandbox Code Playgroud)
我有一个例外:
无法将字符串'[1,1]'转换为字典键类型'System.Collections.Generic.KeyValuePair`2 [System.Int64,System.Int64]'.创建TypeConverter以将字符串转换为键类型对象.路径'[1,1]',第2行,第12位.
那么有人能告诉我正确的代码吗?
这是我的代码:
var test = new ConcurrentDictionary<KeyValuePair<long, long>, IList<string>>();
test.TryAdd(new KeyValuePair<long, long>(1, 1), new List<string> { "Test" });
var se = SerializeObject(test);
var de …Run Code Online (Sandbox Code Playgroud)