自定义工作流程活动错误“值不能为空”

发布于 2024-10-05 08:47:32 字数 2483 浏览 14 评论 0原文

我正在 VS2010 中创建一个针对 .NET 3.5 的自定义工作流活动。该 DLL 实际上正在 Microsoft System Center Service Manager 自定义工作流程中使用,但我认为这不是我的问题。

我有一个公共字符串属性,用户可以输入活动应使用的字符串。但是,当 WF 运行时,它会出错“值不能为空”。我想确定它是我的代码还是其他东西。

当我们将自定义活动拖到设计器上时,我可以在设计器上输入该属性的字符串文本。

public static DependencyProperty ChangeRequestStageProperty = DependencyProperty.Register("ChangeRequestStage", typeof(String), typeof(UpdateChangeRequestStage));

    [DescriptionAttribute("The value to set the ChangeRequestStage Property in the ChangeRequest Extension class.")]
    [CategoryAttribute("Change Request Extension")]
    [BrowsableAttribute(true)]
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    public String Stage
    {
        get { return ((String)(base.GetValue(UpdateChangeRequestStage.ChangeRequestStageProperty))); }
        set { base.SetValue(UpdateChangeRequestStage.ChangeRequestStageProperty, value); }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        EnterpriseManagementGroup emg = CreateEMG();

        //System.WorkItem.ChangeRequest Extension - ClassExtension_928bec0a_cac4_4a0a_bd89_7146c9052fbe
        ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c6c6057-56ad-3862-47ec-dc0dde80a071"));

        //System.WorkItemContainsActivity Relationship Class
        ManagementPackRelationship workItemContainsActivityRelationship = emg.EntityTypes.GetRelationshipClass(new Guid("2DA498BE-0485-B2B2-D520-6EBD1698E61B"));

        EnterpriseManagementObject changeRequest = null;

        //Loop thru each emo (Change Request in this case), and assign it. There will never be more than 1 emo returned
        foreach (EnterpriseManagementObject obj in emg.EntityObjects.GetRelatedObjects<EnterpriseManagementObject>(executionContext.ContextGuid, workItemContainsActivityRelationship, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
        { changeRequest = obj; }

        EnterpriseManagementObjectProjection emop = new EnterpriseManagementObjectProjection(changeRequest);

        if (emop != null)
        { emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage; }

        emop.Commit();

        return base.Execute(executionContext);
    }

由于它收到“值不能为空”错误,我猜测它在这一行:

emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage;

我将测试并查看对值进行硬编码是否有效。有什么想法吗? 在此输入代码

I'm creating a custom workflow activity in VS2010 targeting .NET 3.5. The DLL is actually being used in a Microsoft System Center Service Manager custom workflow, but I don't think that is my issue.

I have a public string property, that the user types in the string of what the activity should use. However, when the WF runs, it errors out 'value cannot be null'. I want to target if it is my code or something else.

When we drag my custom activity onto the designer, I'm able to type in the text of the string on the designer for that property.

public static DependencyProperty ChangeRequestStageProperty = DependencyProperty.Register("ChangeRequestStage", typeof(String), typeof(UpdateChangeRequestStage));

    [DescriptionAttribute("The value to set the ChangeRequestStage Property in the ChangeRequest Extension class.")]
    [CategoryAttribute("Change Request Extension")]
    [BrowsableAttribute(true)]
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    public String Stage
    {
        get { return ((String)(base.GetValue(UpdateChangeRequestStage.ChangeRequestStageProperty))); }
        set { base.SetValue(UpdateChangeRequestStage.ChangeRequestStageProperty, value); }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        EnterpriseManagementGroup emg = CreateEMG();

        //System.WorkItem.ChangeRequest Extension - ClassExtension_928bec0a_cac4_4a0a_bd89_7146c9052fbe
        ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c6c6057-56ad-3862-47ec-dc0dde80a071"));

        //System.WorkItemContainsActivity Relationship Class
        ManagementPackRelationship workItemContainsActivityRelationship = emg.EntityTypes.GetRelationshipClass(new Guid("2DA498BE-0485-B2B2-D520-6EBD1698E61B"));

        EnterpriseManagementObject changeRequest = null;

        //Loop thru each emo (Change Request in this case), and assign it. There will never be more than 1 emo returned
        foreach (EnterpriseManagementObject obj in emg.EntityObjects.GetRelatedObjects<EnterpriseManagementObject>(executionContext.ContextGuid, workItemContainsActivityRelationship, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
        { changeRequest = obj; }

        EnterpriseManagementObjectProjection emop = new EnterpriseManagementObjectProjection(changeRequest);

        if (emop != null)
        { emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage; }

        emop.Commit();

        return base.Execute(executionContext);
    }

Since it is getting a 'value cannot be null' error, I'm guessing it's on this line:

emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage;

I'm going to test and see if hardcoding a value works or not. Any ideas?
enter code here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

调妓 2024-10-12 08:47:32

试试这个

if (emop != null && emop.Object[mpcChangeRequest, "ChangeRequestStage"] != null)
   emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage

try this

if (emop != null && emop.Object[mpcChangeRequest, "ChangeRequestStage"] != null)
   emop.Object[mpcChangeRequest, "ChangeRequestStage"].Value = Stage
ˉ厌 2024-10-12 08:47:32

我不想让这个问题悬而未决,所以我正在更新我如何解决这个问题(很久以前)。

我没有使用 EnterpriseManagementObjectProjection (emop),而是使用标准 EnterpriseManagementObject (emo)。从那里,我能够遵循上面类似的格式:

ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c246fc5-4e5e-0605-dc23-91f7a362615b"));
changeRequest[mpcChangeRequest, "ChangeRequestStage"].Value = this.Stage;
changeRequest.Commit();

I didn't want to leave this question wide open, so I'm updating it as to how I resolved this (a long time ago).

Rather than working with an EnterpriseManagementObjectProjection (emop), I worked with a standard EnterpriseManagementObject (emo). From there, I was able to follow a similar format from above:

ManagementPackClass mpcChangeRequest = emg.EntityTypes.GetClass(new Guid("8c246fc5-4e5e-0605-dc23-91f7a362615b"));
changeRequest[mpcChangeRequest, "ChangeRequestStage"].Value = this.Stage;
changeRequest.Commit();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文