CRM插件:沙盒中的自定义异常 [英] CRM Plugin: Custom Exception in Sandbox

查看:265
本文介绍了CRM插件:沙盒中的自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在沙箱中的动态CRM 2013的插件执行。

这code具有以下自定义异常类:

  [Serializable接口]
    公共类PluginValidationException:异常
    {
        公共PluginValidationException()
        {
        }

        保护PluginValidationException(SerializationInfo中的信息,的StreamingContext上下文)
            :基地(信息,上下文)
        {
        }

        公共PluginValidationException(字符串消息)
            :碱(消息)
        {
        }

        公共PluginValidationException(字符串消息,异常内)
            :基地(消息,内部)
        {
        }
    }
 

在这个异常被抛出在它导致一般性错误窗口插件,并在日志文件中没有详细说明:

未处理的异常:System.ServiceModel.FaultException`1 [Microsoft.Xrm.Sdk.OrganizationServiceFault,Microsoft.Xrm.Sdk,版本= 6.0.0.0,文化=中性公钥= 31bf3856ad364e35]:系统。 Runtime.Serialization.SerializationException:Microsoft Dynamics CRM中遇到错误。参考号码为管理员或支持:#1355B4E4Detail:   -2147220970               调用堆栈          在Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal()    在Microsoft.Crm.Application.Platform.ServiceCommands.CreateCommand.Execute()    在Microsoft.Crm.Application.Platform.EntityProxy.Create(布尔performDuplicateCheck中GUID auditingTransactionId)    在Microsoft.Crm.Application.Platform.EntityProxy.Create(布尔performDuplicateCheck)    在Microsoft.Crm.Application.Platform.EntityProxy.CreateAndRetrieve(字符串[] columnSet,布尔performDuplicateCheck)    在Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.UpdateEntity(实体的实体,布尔检索)    在Microsoft.Crm.Application.WebServices.InlineEdit.SaveCommand.ExecuteCommand(字符串commandXml)    在Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.Execute(字符串commandXml)           System.Runtime.Serialization.SerializationException:Microsoft Dynamics CRM中遇到错误。参考号码为管理员或支持:#1355B4E4   2014-04-06T02:04:30.0972001Z       [Demo.DemoPlugin:Demo.DemoPlugin.BasicCrmPlugin] [d86b89ab-f1bc-e311-9408-000c29254b18:Demo.DemoPlugin.BasicCrmPlugin:创建联系人]

纵观CRM跟踪日志显示以下内容:

System.Runtime.Serialization.SerializationException:组装型Demo.Helpers.PluginValidationException'Demo.DemoPlugin,版本= 1.0.0.0,文化=中性公钥= fbb51ba1e588d276'未标记为可序列化。            在Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IServiceEndpointNotificationService serviceBusService,IOrganizationServiceFactory organizationServiceFactory,字符串pluginTypeName,字符串pluginConfiguration,字符串pluginSecureConfig,IPluginExecutionContext的RequestContext)            在Microsoft.Crm.Sandbox.SandboxWorker.Execute(SandboxCallInfo callInfo,SandboxPluginExecutionContext的RequestContext中GUID pluginAssemblyId,的Int32 sourceHash,字符串的AssemblyName中GUID pluginTypeId,字符串pluginTypeName,字符串pluginConfiguration,字符串pluginSecureConfig,SandboxRequestCounter和放大器; workerCounter)

我不这样做,根据一些阅读,认为这是一个错误 - 而这是因为自定义的异常班都没有,本来值得信赖作为.NET 4(我敢使用.NET 4.5。)

有谁知道如何使将与CRM沙箱中的自定义异常类。我使用的是自定义异常类,因为我发现错误,需要区分的 InvalidPluginExecutionException 异常造成的,因为插件未正确注册。

已更新2014年4月8日

下面是code中,捕获异常,有显著简化了把它放在#1插件:

 尝试
        {
            // TODO:prevalidation逻辑
            ValidatePluginExecution(crmContext,记录,出注册表项目);
            // TODO:Postvalidation逻辑
        }
        赶上(PluginValidationException前)
        {
            // TODO:具体日志记录插件验证异常
            抛出新InvalidPluginExecutionException(无法验证);
        }
        赶上(InvalidPluginExecutionException前)
        {
            logging.Write(InvalidPluginExectionException在插件验证);
            扔;
        }
        赶上(例外前)
        {
            logging.Write(未处理Exeception在插件验证操作);
            logging.Write(前);
            抛出新InvalidPluginExecutionException(错误下载登录并提交给帮助台。前);
        }
 

解决方案

我不认为你想要什么是可能的,如果你想在错误对话框,你不得不放弃 InvalidPluginExecutionException

处理的插件

  

有关同步插件,您可以选择显示自定义错误   通过在Web应用程序的错误对话框消息您   插件引发InvalidPluginExecutionException异常的   自定义消息字符串作为异常消息属性值

     

建议插件只传递   InvalidPluginExecutionException回到该平台。

作为一个方面,我不会理会在插件本身检查登记,它的这种情况不使一个很大的意义在2013年早在CRM 4中的插件必须手动注册的有一些道理在里面。现在我们有解决方案,正确的注册是一个开发和测试任务 - 而不是一个运行时检查

I have a Dynamics CRM 2013 plugin executing in the Sandbox.

This code has the following custom exception class:

    [Serializable]
    public class PluginValidationException : Exception
    {
        public PluginValidationException()
        {
        }

        protected PluginValidationException(SerializationInfo info, StreamingContext context) 
            : base(info, context)
        {            
        }

        public PluginValidationException(string message)
            : base(message)
        {
        }

        public PluginValidationException(string message, Exception inner)
            : base(message, inner)
        {
        }
    }

When this exception is thrown in the plugin it results in a generic error window, with no details in the log file:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #1355B4E4Detail: -2147220970 CallStack at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal() at Microsoft.Crm.Application.Platform.ServiceCommands.CreateCommand.Execute() at Microsoft.Crm.Application.Platform.EntityProxy.Create(Boolean performDuplicateCheck, Guid auditingTransactionId) at Microsoft.Crm.Application.Platform.EntityProxy.Create(Boolean performDuplicateCheck) at Microsoft.Crm.Application.Platform.EntityProxy.CreateAndRetrieve(String[] columnSet, Boolean performDuplicateCheck) at Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.UpdateEntity(Entity entity, Boolean retrieve) at Microsoft.Crm.Application.WebServices.InlineEdit.SaveCommand.ExecuteCommand(String commandXml) at Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.Execute(String commandXml) System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #1355B4E4 2014-04-06T02:04:30.0972001Z [Demo.DemoPlugin: Demo.DemoPlugin.BasicCrmPlugin] [d86b89ab-f1bc-e311-9408-000c29254b18: Demo.DemoPlugin.BasicCrmPlugin: Create of contact]

Looking at the CRM trace log shows the following:

System.Runtime.Serialization.SerializationException: Type 'Demo.Helpers.PluginValidationException' in assembly 'Demo.DemoPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fbb51ba1e588d276' is not marked as serializable. at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IServiceEndpointNotificationService serviceBusService, IOrganizationServiceFactory organizationServiceFactory, String pluginTypeName, String pluginConfiguration, String pluginSecureConfig, IPluginExecutionContext requestContext) at Microsoft.Crm.Sandbox.SandboxWorker.Execute(SandboxCallInfo callInfo, SandboxPluginExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String pluginConfiguration, String pluginSecureConfig, SandboxRequestCounter& workerCounter)

I do not, based on some reading, believe this is a bug - rather it is because custom Exception classes are not, inherently trusted as of .NET 4 (I'm using .NET 4.5.)

Does anyone know how to make a custom exception class that will work with the CRM Sandbox. I'm using a custom exception class because I catch errors and need to distinguish between an InvalidPluginExecutionException an exception caused because the plug-in is incorrectly registered.

UPDATED Apr 08 2014

Here is the code in the plugin that catches the exceptions, with significant simplification for putting it on Stackoverflow:

        try
        {
            //TODO: Prevalidation Logic
            ValidatePluginExecution(crmContext, logging, out keyName);
            //TODO: Postvalidation Logic
        }
        catch (PluginValidationException ex)
        {
            //TODO: Specific logging for Plugin Validation Exception
            throw new InvalidPluginExecutionException("Did Not Validate");                    
        }
        catch (InvalidPluginExecutionException ex)
        {
            logging.Write("InvalidPluginExectionException at Plugin Validation");                    
            throw;
        }
        catch (Exception ex)
        {
            logging.Write("Unhandled Exeception During Plugin Validation Operation");
            logging.Write(ex);
            throw new InvalidPluginExecutionException("Error.  Download Log and submit to the Help Desk.", ex);                    
        }

解决方案

I don't think what you want is possible, if you want a message in that error dialog you have to throw InvalidPluginExecutionException.

Handle Exceptions in Plug-Ins

For synchronous plug-ins, you can optionally display a custom error message in the error dialog of the web application by having your plug-in throw an InvalidPluginExecutionException exception with the custom message string as the exception Message property value

It is recommended that plug-ins only pass an InvalidPluginExecutionException back to the platform.

As a side, I wouldn't bother checking the registration in the plugin itself, its a situation which doesn't make a lot of sense in 2013. Back in CRM 4 where plugins had to be manually registered there was some sense in it. Now we have solutions, the correct registration is a development and testing task - not a run time check.

这篇关于CRM插件:沙盒中的自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆