Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i solve this exception,i hope get help from here,thanks
C#
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)
                        {
                            //Error in 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;
        }   


Class DTOWrapper:
C#
[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();
    }


Then throw exception:
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)
       at System.Runtime.Serialization.DataContractSerializer..ctor(Type type, IEnumerable`1 knownTypes, Int32 maxItemsInObjectGraph, Boolean ignoreExtensionDataObject, Boolean preserveObjectReferences, IDataContractSurrogate dataContractSurrogate, DataContractResolver dataContractResolver)
       at System.Runtime.Serialization.DataContractSerializer..ctor(Type type, IEnumerable`1 knownTypes, Int32 maxItemsInObjectGraph, Boolean ignoreExtensionDataObject, Boolean preserveObjectReferences, IDataContractSurrogate dataContractSurrogate)
       at System.Runtime.Serialization.DataContractSerializer..ctor(Type type, IEnumerable`1 knownTypes)
       at System.Runtime.Serialization.DataContractSerializer..ctor(Type type)
       at Achievo.ServiceManager.ServiceModel.DTOWrapper.Deserialize(Type t, String data)
       at Achievo.ServiceManager.ServiceModel.DTOWrapper.Unwrap()
       at Achievo.Workflow.Runtime.WorkflowRuntimeEndpoint.OnGetCreationContext(Object[] inputs, OperationContext operationContext, Guid instanceId, WorkflowHostingResponseContext responseContext)
       at System.ServiceModel.Activities.Dispatcher.PersistenceContext.GetInstance(WorkflowGetInstanceContext parameters)
       at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.GetInstanceAsyncResult.TryAcquire(Boolean fromCache)
       at System.ServiceModel.Activities.Dispatcher.DurableInstanceManager.GetInstanceAsyncResult.HandleEndLoad(IAsyncResult result)
       at System.Runtime.AsyncResult.AsyncCompletionWrapperCallback(IAsyncResult result)
  InnerException:
Posted
Updated 29-Apr-14 0:21am
v3

Hello tanghuawei,

System.ArgumentNullException is because you forgot to check if a value code be passed as null by the code or the user.

Debug your code to see what is coming as NULL and treat it. If it meant to come like that, you can add a " ??xx " after the variable and standard value in the place of xx you would want to use instead.

example
C#
String aString = MethodReturningString()?? " ";
//or

//nullable int
int? num;

MethodThatPassesInt(num??5);


If you something really needs to be passed, then maybe you should make sure you have data to work with. Do a if/else clause or a try/catch; the one who who better serves your purpose
 
Share this answer
 
thanks for you help,but the same xml file unwrap in workflow started is fine, unwrap at runtime end point throw ArgumentNullException.

Xml file:
XML
<donationrequestdto xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Achievo.Service.WorkFlowForm.Contract"><createdby i:nil="true" /><createddate i:nil="true" /><updatedby i:nil="true" /><updateddate i:nil="true" /><amountoffunding>11</amountoffunding><applicant>Administrator</applicant><applicantid>2</applicantid><approveridsearch>0</approveridsearch><approvernamesearch i:nil="true" /><approvernames i:nil="true" /><approvingstatus i:nil="true" /><assistant>Administrator</assistant><assistantid>2</assistantid><assoinfo i:nil="true" /><authorid>2</authorid><budgeted>false</budgeted><category>General Donation</category><dd>11111</dd><dateofrequestororrecipientrequest>2014-04-30T00:00:00</dateofrequestororrecipientrequest><descriptionofhowfundwillbeused>111</descriptionofhowfundwillbeused><detaileddescriptionoftype>1111</detaileddescriptionoftype><duediligenceperformeddate>2014-04-30T09:16:06</duediligenceperformeddate><editingstatus>Draft</editingstatus><explain>false</explain><explanationmakingproposeddonation>111</explanationmakingproposeddonation><filedescription i:nil="true" /><FormName>Donation</FormName><fromformid i:nil="true" /><id>310</id><intvalueofeditingstatus>1</intvalueofeditingstatus><nature>Nature1</nature><natureid>1</natureid><nextduediligencereviewdate>2014-04-30T09:16:07</nextduediligencereviewdate><ownerid>2</ownerid><postevent i:nil="true" /><productbrandids xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:int>9</d2p1:int></productbrandids><productbrandnames>Cubicin</productbrandnames><proposeenddateofsupport>2014-04-30T00:00:00+08:00</proposeenddateofsupport><proposeenddateofsupportfrom>0001-01-01T00:00:00</proposeenddateofsupportfrom><proposeenddateofsupportto>2014-05-01T00:00:00</proposeenddateofsupportto><proposestartdateofsupport>2014-04-30T00:00:00+08:00</proposestartdateofsupport><proposestartdateofsupportfrom>0001-01-01T00:00:00</proposestartdateofsupportfrom><proposestartdateofsupportto>2014-04-30T00:00:00</proposestartdateofsupportto><recipientid>3</recipientid><recipientname>Against Child Abuse Ltd</recipientname><remarks i:nil="true" /><representationorsuggestion i:nil="true" /><requestno>EG14000057</requestno><revisionno i:nil="true" /><showstatusstring i:nil="true" /><sort i:nil="true" /><sortdir i:nil="true" /><specificifothers i:nil="true" /><status i:nil="true" /><submitdate>2014-04-30T09:16:19.6339099+08:00</submitdate><submitdatefrom>0001-01-01T00:00:00</submitdatefrom><submitdateto>0001-01-01T00:00:00</submitdateto><supportingfiletoattach /><urgent>Normal</urgent><usedfunddescription i:nil="true" /><userid>2</userid><workflowinstanceid>0</workflowinstanceid><workflowname>Donation</workflowname><workflowversionid>41</workflowversionid></donationrequestdto>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900