Vb.net CRM 2011插件例外

Vb.net CRM 2011插件例外,vb.net,plugins,dynamics-crm-2011,dynamics-crm,Vb.net,Plugins,Dynamics Crm 2011,Dynamics Crm,我的插件没有显示异常,这是我遇到的问题,尽管它的行为是正确的,因为它没有保存,但只在一种情况下显示。以下是场景: 我们有一个实体,每个业务单元只能存在一个活动实体。我有检测激活、分配和创建的插件,所有这些插件都会检查工件的拥有业务单元,如果是重复的,则抛出异常 当通过按顶部的Assign按钮或按owner字段旁边的放大镜来调用Assign时,这适用于create、on activate和on Assign。下面的图片很有用。 但是,如果用户在文本框中键入新的所有者名称并选择一个用户,然后按sa

我的插件没有显示异常,这是我遇到的问题,尽管它的行为是正确的,因为它没有保存,但只在一种情况下显示。以下是场景:

我们有一个实体,每个业务单元只能存在一个活动实体。我有检测激活、分配和创建的插件,所有这些插件都会检查工件的拥有业务单元,如果是重复的,则抛出异常

当通过按顶部的Assign按钮或按owner字段旁边的放大镜来调用Assign时,这适用于create、on activate和on Assign。下面的图片很有用。

但是,如果用户在文本框中键入新的所有者名称并选择一个用户,然后按save,则会调用assign插件,并阻止更改,但不会出现异常消息框。我使用了我们的内部日志系统,看到异常行被命中,但仍然没有显示

Public Class OurEntityPreAssign
    Implements IPlugin

    Public Sub Execute(ByVal serviceProvider As System.IServiceProvider) Implements Microsoft.Xrm.Sdk.IPlugin.Execute
        Dim context As IPluginExecutionContext = CType(serviceProvider.GetService(GetType(IPluginExecutionContext)), IPluginExecutionContext)
        Dim factory As IOrganizationServiceFactory = CType(serviceProvider.GetService(GetType(Microsoft.Xrm.Sdk.IPluginExecutionContext)), IOrganizationServiceFactory)
        Dim service As IOrganizationService = factory.CreateOrganizationService(context.UserId)
        Dim entity As Entity
        ' Get Assignee
        ' Compare it to the PreImage
        ' If Same BUID, do nothing
        ' Else check for duplicate
        ErrorLogUtil.WriteToFile("PreAssign") '--> This gets logged
        If context.InputParameters.Contains("Assignee") AndAlso TypeOf context.InputParameters("Assignee") Is EntityReference Then
            Dim assigneeER As EntityReference = CType(context.InputParameters("Assignee"), EntityReference)
            entity = service.Retrieve(assigneeER.LogicalName, assigneeER.Id, New Microsoft.Xrm.Sdk.Query.ColumnSet(True))

            Dim er As EntityReference = CType(entity.Attributes("businessunitid"), EntityReference)
            Dim initialBusinessUnit As EntityReference = CType(context.PreEntityImages("PreImage").Attributes("owningbusinessunit"), EntityReference)

            ErrorLogUtil.WriteToFile("initialBusinessUnitID:" & initialBusinessUnit.Id.ToString & ", assigneeER: " & er.Id.ToString)' -->These values are different, which means we need to check to see if the new one already has a record

            If Not er.Id = initialBusinessUnit.Id Then
                If Not er.Name = "Disabled Users" Then
                    If OurEntity.isDuplicate(er.Id, service, context.PreEntityImages("PreImage").LogicalName) Then
                        ErrorLogUtil.WriteToFile("ExceptionThrown") '-->This is being hit, which means that the throw call should also be hit, or some other error should appear
                        Throw New InvalidPluginExecutionException("My Message Here")
                    End If
                End If
            End If
        End If
    End Sub

End Class
很明显,我已经看过了,但没有任何答案,这确实是一个不同的问题,因为询问者至少收到了某种错误信息


还有其他人经历过这种情况吗?

不知道为什么没有收到错误框。一种解决方案是在更新消息上注册插件。 当用户分配记录时,更新消息将在分配消息之前激发。 您可以检查目标实体是否包含ownerid字段。如果它确实运行比较检查并抛出错误


HTH

您是否尝试过使用InvalidPlugineExecutionException的构造函数来接受消息和异常

因此,不是:

Throw New InvalidPluginExecutionException("My Message Here")
比如:

Throw New InvalidPluginExecutionException("My Message Here", new FaultException<OrganizationServiceFault>())