Ask a questionAsk a question
 

QuestionRuleSyntaxException occurred

  • Saturday, November 07, 2009 4:49 PMnandsnyou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi everyone.
    I am working on Hosting the Designer. After refering to this
    I did Debug->Exceptions->CLR Exceptions
    After loading the xoml file when I go through
    DynamicUpdateCondition property->Declarative Rule Condition->Condition Name->Select Condition->New Condition
    I get the following exception:
    "RuleSyntaxException occurred. The condition can not be empty."
    What do I need to do?

    Thanks in advance.

    Below is my full code;

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel.Design;
    using System.ComponentModel.Design.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.Activities;
    using System.Workflow.ComponentModel.Design;
    using System.Runtime.InteropServices;
    using System.Collections;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Xml;
    using System.Workflow.ComponentModel.Serialization;
    using System.Drawing.Design;
     
     
    namespace WF29_10
    {
        public partial class WFDControl : Form, IServiceProvider, ISite
        {
     
            private WorkflowView workflowView;
            private IDesignerHost designerHost;
     
            public WFDControl()
            {
                InitializeComponent();
     
              
            }
     
            private void WFDControl_Load(object sender, EventArgs e)
            {
                InitialiseWorkflow();
     
                if (designerHost != null)
                {
                    designerHost.RemoveService(typeof(IIdentifierCreationService));                
                    designerHost.AddService(typeof(IMenuCommandService), new WorkflowMenuCommandService(designerHost));               
                    TypeProvider typeProvider = new TypeProvider(designerHost);
                    typeProvider.AddAssemblyReference(typeof(string).Assembly.Location);
                    designerHost.AddService(typeof(ITypeProvider), typeProvider, true);
                  
                }
     
                InitialiseSelectionChangedHandler();
     
                InitialiseToolbox();
     
            }
     
     
     
     
            # region Menu Command
     
            internal sealed class WorkflowMenuCommandService : MenuCommandService
            {
                public WorkflowMenuCommandService(IServiceProvider serviceProvider)
                    : base(serviceProvider)
                {
                }
     
                public override void ShowContextMenu(CommandID menuID, int x, int y)
                {
                    if (menuID == WorkflowMenuCommands.SelectionMenu)
                    {
                        ContextMenu contextMenu = new ContextMenu();
     
                        foreach (DesignerVerb verb in Verbs)
                        {
                            MenuItem menuItem = new MenuItem(verb.Text, new EventHandler(OnMenuClicked));
                            menuItem.Tag = verb;
                            contextMenu.MenuItems.Add(menuItem);
                        }
     
                        MenuItem[] items = GetSelectionMenuItems();
                        if (items.Length > 0)
                        {
                            contextMenu.MenuItems.Add(new MenuItem("-"));
                            foreach (MenuItem item in items)
                                contextMenu.MenuItems.Add(item);
                        }
     
                        WorkflowView workflowView = GetService(typeof(WorkflowView)) as WorkflowView;
                        if (workflowView != null)
                            contextMenu.Show(workflowView, workflowView.PointToClient(new Point(x, y)));
                    }
                }
     
                private MenuItem[] GetSelectionMenuItems()
                {
                    List<MenuItem> menuItems = new List<MenuItem>();
     
                    bool addMenuItems = true;
                    ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
                    if (selectionService != null)
                    {
                        foreach (object obj in selectionService.GetSelectedComponents())
                        {
                            if (!(obj is Activity))
                            {
                                addMenuItems = false;
                                break;
                            }
                        }
                    }
     
                    if (addMenuItems)
                    {
                        Dictionary<CommandID, string> selectionCommands = new Dictionary<CommandID, string>();
                        selectionCommands.Add(WorkflowMenuCommands.Cut, "Cut");
                        selectionCommands.Add(WorkflowMenuCommands.Copy, "Copy");
                        selectionCommands.Add(WorkflowMenuCommands.Paste, "Paste");
                        selectionCommands.Add(WorkflowMenuCommands.Delete, "Delete");
                        selectionCommands.Add(WorkflowMenuCommands.Collapse, "Collapse");
                        selectionCommands.Add(WorkflowMenuCommands.Expand, "Expand");
                        selectionCommands.Add(WorkflowMenuCommands.Disable, "Disable");
                        selectionCommands.Add(WorkflowMenuCommands.Enable, "Enable");
     
                        foreach (CommandID id in selectionCommands.Keys)
                        {
                            MenuCommand command = FindCommand(id);
                            if (command != null)
                            {
                                MenuItem menuItem = new MenuItem(selectionCommands[id], new EventHandler(OnMenuClicked));
                                menuItem.Tag = command;
                                menuItems.Add(menuItem);
                            }
                        }
                    }
     
                    return menuItems.ToArray();
                }
     
                private void OnMenuClicked(object sender, EventArgs e)
                {
                    MenuItem menuItem = sender as MenuItem;
                    if (menuItem != null && menuItem.Tag is MenuCommand)
                    {
                        MenuCommand command = menuItem.Tag as MenuCommand;
                        command.Invoke();
                    }
                }
            }
     
            # endregion
     
            #region ISite Members
     
            IComponent ISite.Component
            {
                get { return this; }
            }
     
            IContainer ISite.Container
            {
                get { return this.Container; }
            }
     
            bool ISite.DesignMode
            {
                get { return true; }
            }
     
            string ISite.Name
            {
                get
                {
                    return this.Name;
                }
                set
                {
                    this.Name = value;
                }
            }
     
            #endregion
     
            #region IServiceProvider Members
     
            object IServiceProvider.GetService(Type serviceType)
            {
                return this.GetService(serviceType);
            }
     
            #endregion
        
     
            private void InitialiseToolbox()
            {
                MyToolboxService toolboxService = new MyToolboxService();
     
                designerHost.AddService(typeof(IToolboxService),
                  toolboxService);
     
                myToolboxListView1.ServiceProvider = designerHost;
     
                myToolboxListView1.InitialiseToolboxItems();
            }
     
     
     
            private void InitialiseWorkflow()
            {
                DesignSurface designSurface = new DesignSurface();
                WorkflowLoader loader = new WorkflowLoader();
     
                designSurface.BeginLoad(loader);
                designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
                
            }
     
            private void LoadWorkflow()
            {
                if (designerHost != null && designerHost.RootComponent != null)
                {
                    this.propertyGrid1.Site = designerHost.RootComponent.Site;
                    IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
                    if (rootDesigner != null)
                    {
                      
                        this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
                        this.panel1.Controls.Add(this.workflowView);
                        this.workflowView.Dock = DockStyle.Fill;
                        this.workflowView.TabIndex = 1;
                        this.workflowView.TabStop = true;
                        this.workflowView.HScrollBar.TabStop = false;
                        this.workflowView.VScrollBar.TabStop = false;
                        this.workflowView.Focus();
                        this.workflowView.FitToScreenSize();
                    }
                }
            }
     
            private void openToolStripMenuItem_Click(object sender, EventArgs e)
            {
                string fileName = GetFileName();
     
                if (fileName != null)
                {
                    Activity rootActivity = LoadWorkflowFromFile(fileName);
     
                    if (rootActivity != null)
                    {
                        AddActivityToDesigner(rootActivity);
     
                        LoadWorkflow();
     
                        SelectRootActivity();
     
                    }
                }
     
            }
     
            private void SelectRootActivity()
            {
                ISelectionService selectionService =
                  GetHostService<ISelectionService>();
     
                selectionService.SetSelectedComponents(
                  new object[] { designerHost.RootComponent });
            }
            private void InitialiseSelectionChangedHandler()
            {
                ISelectionService selectionService =
                  GetHostService<ISelectionService>();
     
                selectionService.SelectionChanged +=
                  new EventHandler(OnSelectionChanged);
            }
            void OnSelectionChanged(object sender, EventArgs e)
            {
                ISelectionService selectionService =
                  GetHostService<ISelectionService>();
     
                propertyGrid1.SelectedObjects =
                  (object[])selectionService.GetSelectedComponents();
            }
            private T GetHostService<T>() where T : class
            {
                T service = designerHost.GetService(typeof(T)) as T;
                return (service);
            }
     
     
            private void AddActivityToDesigner(Activity rootActivity)
            {
               
                designerHost.Container.Add(rootActivity);
     
               
                CompositeActivity compositeActivity = rootActivity as CompositeActivity;
     
                if (compositeActivity != null)
                {
                    foreach (Activity childActivity in compositeActivity.Activities)
                    {
                        
                        AddActivityToDesigner(childActivity);
                    }
                }
            }
            private static Activity LoadWorkflowFromFile(string fileName)
            {
                ActivityMarkupSerializer serializer = new ActivityMarkupSerializer();
                Activity activity = null;
     
                using (XmlReader reader = XmlReader.Create(fileName))
                {
                    activity = serializer.Deserialize(reader) as Activity;
                }
                return (activity);
            }
            private static string GetFileName()
            {
                string fileName = null;
     
                OpenFileDialog d = new OpenFileDialog();
                d.Title = "Select XAML based Workflow";
                d.Filter = "XAML Files (*.xoml)|*.xoml|All Files (*.*)|*.*";
     
                if (d.ShowDialog() == DialogResult.OK)
                {
                    fileName = d.FileName;
                }
                return (fileName);
            }
     
        }
    }

    • Edited bynandsnyou Tuesday, November 10, 2009 10:14 AMCode added
    •  

All Replies

  • Wednesday, November 11, 2009 6:19 AMAndrew_ZhuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Could you paste the full exception trace stack?
    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
  • Thursday, November 12, 2009 4:25 AMnandsnyou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Here is what Call Stack window shows:

         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Parser.ParseCondition(string expressionString) + 0x11c bytes     
         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Design.RuleConditionDialog.InitializeDialog(System.CodeDom.CodeExpression expression) + 0x17c bytes     
         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Design.RuleConditionDialog.RuleConditionDialog(System.Workflow.ComponentModel.Activity activity, System.CodeDom.CodeExpression expression) + 0x1dd bytes     
         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Design.ConditionBrowserDialog.OnNewInternal() + 0x33 bytes     
         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Design.BasicBrowserDialog.OnNew(object sender, System.EventArgs e) + 0x2a bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.RaiseEvent(object key, System.EventArgs e) + 0x41 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripButton.OnClick(System.EventArgs e) + 0x3e bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleClick(System.EventArgs e) + 0xc7 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.HandleMouseUp(System.Windows.Forms.MouseEventArgs e = {X = 33 Y = 14 Button = Left}) + 0x220 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEventInteractive(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x87 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStripItem.FireEvent(System.EventArgs e, System.Windows.Forms.ToolStripItemEventType met) + 0x122 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnMouseUp(System.Windows.Forms.MouseEventArgs mea) + 0xc7 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0xf2 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x544 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) + 0x45 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {msg=0x202 (WM_LBUTTONUP) hwnd=0x50538 wparam=0x0 lparam=0xf0021 result=0x0}) + 0x71 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes     
         [Native to Managed Transition]     
         [Managed to Native Transition]     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = 4, int pvLoopData = 0) + 0x2ea bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = 4, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.Application.ModalApplicationContext}) + 0x17d bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x4ee bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.ShowDialog(System.Windows.Forms.Form dialog) + 0x17a bytes     
         System.Workflow.Activities.dll!System.Workflow.Activities.Rules.Design.ConditionNameEditor.EditValue(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, System.IServiceProvider serviceProvider, object o) + 0xff bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.GridEntry.EditPropertyValue(System.Windows.Forms.PropertyGridInternal.PropertyGridView iva = {System.Windows.Forms.PropertyGridInternal.PropertyGridView}) + 0x4c bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry.EditPropertyValue(System.Windows.Forms.PropertyGridInternal.PropertyGridView iva) + 0x13 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.PopupDialog(int row) + 0x703 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.PropertyGridView.OnBtnClick(object sender, System.EventArgs e) + 0x87 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x57 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e) + 0x49 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.DropDownButton.OnClick(System.EventArgs e) + 0xe bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent = {X = 10 Y = 8 Button = Left}) + 0xc3 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.PropertyGridInternal.DropDownButton.OnMouseUp(System.Windows.Forms.MouseEventArgs e) + 0xe bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) + 0xf2 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x544 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m) + 0xce bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m) + 0x2b bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0xd6 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 514, System.IntPtr wparam, System.IntPtr lparam) + 0x75 bytes     
         [Native to Managed Transition]     
         [Managed to Native Transition]     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2ea bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes     
         System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes     
    >    WF29_10.exe!WF29_10.Program.Main() Line 17 + 0x1a bytes    C#
         [Native to Managed Transition]     
         [Managed to Native Transition]     
         mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x32 bytes     
         Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes     
         mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes     
         mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes     
         mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes   



  • Monday, November 16, 2009 2:04 AMAndrew_ZhuMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Do you really want a WF3 solution(a question from Mike Taulty)? Since everything has been rewriten in WF4 and it is much easier to do Hosting the Designer job in WF4.

    Regards



    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
  • Wednesday, November 18, 2009 5:51 PMnandsnyou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Currently I am working in VS2005. To use WF4 will I need to shift to VS2008/VS2010?

    Thanks.
  • Monday, November 23, 2009 8:36 AMnandsnyou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Andrew Zhu,

    I want a WF3 solution.

    Thanks.