0
Answer

Serialize Deserialize RuleDefinition

aline badr

aline badr

10y
1.4k
1

Hello, 

I've created Windows workflow RuleDefinition programmatically using the CodeDom objects in the rules object model.

I've serialized into string to save it in SharePoint list, using the method below.
I've deserialized the string to get the object RuleDefinitions using the method below, it returns null and the error message: 
"Could not deserialize object. The type 'http//schemas.microsoft.com/winfx/2006/xaml/workflow.RuleDefinitions' could not be resolved."
 
 
Serialize Method
DesignerSerializationManager dsm = new DesignerSerializationManager(); 
using (dsm.CreateSession()){                     
   StringBuilder stringBuilder = new StringBuilder();                     
   using (XmlTextWriter writer = new XmlTextWriter(new System.IO.StringWriter(stringBuilder))) {    
      WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();                         
      markupSerializer.Serialize(dsm, writer, ruleDeinitions);                         
      string rulesAsString = stringBuilder.ToString();
   }  
}  
Deserialize Method
DesignerSerializationManager dsm = new DesignerSerializationManager();
using (dsm.CreateSession()){                     
   StringBuilder stringBuilder = new StringBuilder();                     
   using (XmlTextReader writer = new XmlTextReader(new System.IO.StringReader(xml)) ) {                        
      reader.Read();                         
      WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();                         
      RuleDefinitions ruleDefinitions = markupSerializer.Deserialize(dsm, reader) as RuleDefinitions;
      if (dsm.Errors.Count > 0){                             
        WorkflowMarkupSerializationException error = dsm.Errors[0] as WorkflowMarkupSerializationException;                            
      }
   }  
} 
 Any idea?
Thanks in advance