.NET Framework Developer Center >
.NET Development Forums
>
Windows Workflow Foundation
>
ReHosting, HandleExternalEvent interface type
ReHosting, HandleExternalEvent interface type
- Hi everyone!I've got a problem with the InterfaceType property in a HandleExternalEvent when a workflow is reloaded in the wf (rehosted) designer.So far I've managed to load the interfaces (in the same way as described in: http://social.msdn.microsoft.com/forums/en-US/windowsworkflowfoundation/thread/2d8bd408-6d30-4510-bfb6-2534d7b7c907/) and everything seems to work as intended when setting the interface type in the designer.However, If I save the Workflow, restart the designer and load the workflow I get an error "!" next to the InterfaceType in the ExternalEvent activity. Strangely, the Interface name is still there (so the property looks like it is set) but there is an error message "Property InterfaceType is not set".Anyone got any idea how I can get started solving this one?Best Regards,Marcus
Answers
- Finally found a solution!The problem was that the Deserialization of the .xoml file failed to assign the correct type object to the InterfaceType property even though the actually type (as a string) is available (see code below).By retrieving the type string, finding the correct Type object, and manually assign it to the InterfaceType property it started to work as expected. The code is done inside the AddObjectToGraphToDesignerHost() method (any constructive feedback on the code is most welcome!):
private static void AddObjectGraphToDesignerHost(IDesignerHost designerHost, Activity activity) { //Code.... if (activity is CompositeActivity) { foreach (Activity activity2 in GetNestedActivities(activity as CompositeActivity)) { HandleExternalEventActivity a = activity2 as HandleExternalEventActivity; //We need to set the InterfaceType property of the HandleExternalEventActivity //since it, by some strange reason, is not set after it has been deserialized. if (a != null) { //HACK: Hardcoded guid to get the interfaceType string, probably not generic solution Guid interfaceTypeGUID = new Guid("8b018fbd-a60e-4378-8a79-8a190ae13eba"); Hashtable values = (Hashtable)a.UserData[interfaceTypeGUID]; //If the value does not exist we should ignore it (it has probably not been set by the user yet). if (values != null) { //Get the DP of the InterfaceType which act as a key to get the Interface type fron userdata DependencyProperty dp = DependencyProperty.FromName("InterfaceType", typeof(HandleExternalEventActivity)); //The type that the InterfaceType should have, represented as a String String typeToFind = null; if (values[dp] != null) typeToFind = values[dp].ToString(); //Find the type in the typeprovider TypeProvider p = (TypeProvider)designerHost.GetService(typeof(ITypeProvider)); List<Type> types = new List<Type>(p.GetTypes()); Type t = types.Where(x => x.FullName == typeToFind).SingleOrDefault(); if (t != null) { //Assign the correct type to the activity a.SetValue(HandleExternalEventActivity.InterfaceTypeProperty, t); } } } designerHost.Container.Add(activity2, activity2.QualifiedName); } } }
- Marked As Answer byMasus_84 Friday, October 30, 2009 9:44 AM
All Replies
- Additional information:If I save the workflow through the rehosted designer and adds the created .xoml file to an existing VS2008 workflow project it is possible to view the saved workflow without any errors.I therefore assume that there is nothing wrong in the .xoml file that is generated by the rehost designer.The only explanation I can come up with is that the designer cannot find the type (or .dll) containing the choosen interface that is bound to the InterfaceType property on the ExternalEventActivity.I've added all the required .dll files to the typeprovider (see post above). Is there something else I need to do?Any help would be most appreciated! I'm totally lost here..
- Finally found a solution!The problem was that the Deserialization of the .xoml file failed to assign the correct type object to the InterfaceType property even though the actually type (as a string) is available (see code below).By retrieving the type string, finding the correct Type object, and manually assign it to the InterfaceType property it started to work as expected. The code is done inside the AddObjectToGraphToDesignerHost() method (any constructive feedback on the code is most welcome!):
private static void AddObjectGraphToDesignerHost(IDesignerHost designerHost, Activity activity) { //Code.... if (activity is CompositeActivity) { foreach (Activity activity2 in GetNestedActivities(activity as CompositeActivity)) { HandleExternalEventActivity a = activity2 as HandleExternalEventActivity; //We need to set the InterfaceType property of the HandleExternalEventActivity //since it, by some strange reason, is not set after it has been deserialized. if (a != null) { //HACK: Hardcoded guid to get the interfaceType string, probably not generic solution Guid interfaceTypeGUID = new Guid("8b018fbd-a60e-4378-8a79-8a190ae13eba"); Hashtable values = (Hashtable)a.UserData[interfaceTypeGUID]; //If the value does not exist we should ignore it (it has probably not been set by the user yet). if (values != null) { //Get the DP of the InterfaceType which act as a key to get the Interface type fron userdata DependencyProperty dp = DependencyProperty.FromName("InterfaceType", typeof(HandleExternalEventActivity)); //The type that the InterfaceType should have, represented as a String String typeToFind = null; if (values[dp] != null) typeToFind = values[dp].ToString(); //Find the type in the typeprovider TypeProvider p = (TypeProvider)designerHost.GetService(typeof(ITypeProvider)); List<Type> types = new List<Type>(p.GetTypes()); Type t = types.Where(x => x.FullName == typeToFind).SingleOrDefault(); if (t != null) { //Assign the correct type to the activity a.SetValue(HandleExternalEventActivity.InterfaceTypeProperty, t); } } } designerHost.Container.Add(activity2, activity2.QualifiedName); } } }
- Marked As Answer byMasus_84 Friday, October 30, 2009 9:44 AM


