当前位置: 代码迷 >> Web Service >> 为什么小弟我反序列化时,总是提示system.argumentnullexception
  详细解决方案

为什么小弟我反序列化时,总是提示system.argumentnullexception

热度:164   发布时间:2016-05-02 02:20:26.0
为什么我反序列化时,总是提示system.argumentnullexception

 protected override WorkflowCreationContext OnGetCreationContext(object[] inputs, OperationContext operationContext, Guid instanceId, WorkflowHostingResponseContext responseContext)
        {
            WorkflowCreationContext creationContext = new WorkflowCreationContext();

            if (operationContext.IncomingMessageHeaders.Action.EndsWith("StartWorkflow"))
            {
                IDictionary<string, object> arguments = (IDictionary<string, object>)inputs[1];

                if (arguments != null && arguments.Count > 0)
                {
                    foreach (KeyValuePair<string, object> pair in arguments)
                    {
                        if (pair.Value is DTOWrapper)
                        {
                            //这句执行Unwrap()时出错
                            creationContext.WorkflowArguments.Add(pair.Key, (pair.Value as DTOWrapper).Unwrap());
                        }
                        else
                            creationContext.WorkflowArguments.Add(pair.Key, pair.Value);
                    }
                }                
            }            
            else
            {
                new Logger(_connectionString)
                    .Log((Guid)inputs[0], "Invalid Action: " + operationContext.IncomingMessageHeaders.Action);
            }

            responseContext.SendResponse(null, null);

            return creationContext;
        }      


DTOWrapper类:

[Serializable]
    [DataContract]
    public class DTOWrapper
    {
        public DTOWrapper();
        public DTOWrapper(object obj);

        [DataMember]
        public string AssemblyName { get; set; }
        [DataMember]
        public string Data { get; set; }
        [DataMember]
        public string DataType { get; set; }

        public object Unwrap();
    }


异常信息:

System.ArgumentNullException was unhandled by user code
  HResult=-2147467261
  Message=Value cannot be null.
Parameter name: type
  Source=System.Runtime.Serialization
  ParamName=type
  StackTrace:
       at System.Runtime.Serialization.XmlObjectSerializer.CheckNull(Object obj, String name)
       at System.Runtime.Serialization.DataContractSerializer.Initialize(Type type, IEnumerable`1 knownTypes, Int32 maxItemsInObjectGraph, Boolean ignoreExtensionDataObject, Boolean preserveObjectReferences, IDataContractSurrogate dataContractSurrogate, DataContractResolver dataContractResolver, Boolean serializeReadOnlyTypes)
  相关解决方案