- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个在沙盒中执行的 Dynamics CRM 2013 插件。
此代码具有以下自定义异常类:
[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)
{
}
}
当在插件中抛出此异常时,它会产生一个通用错误窗口,日志文件中没有详细信息:
未处理的异常: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 遇到错误。管理员或支持人员的引用编号:#1355B4E4详细信息: -2147220970 调用栈 在 Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal() 在 Microsoft.Crm.Application.Platform.ServiceCommands.CreateCommand.Execute() 在 Microsoft.Crm.Application.Platform.EntityProxy.Create( bool performDuplicateCheck,Guid auditingTransactionId) 在 Microsoft.Crm.Application.Platform.EntityProxy.Create( bool performDuplicateCheck) 在 Microsoft.Crm.Application.Platform.EntityProxy.CreateAndRetrieve(String[] columnSet,Boolean performDuplicateCheck) 在 Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.UpdateEntity(实体实体, bool 检索) 在 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.DemoPlugin,Version=1.0.0.0,Culture=neutral,PublicKeyToken=fbb51ba1e588d276”中的类型“Demo.Helpers.PluginValidationException”未标记为可序列化。 在 Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IServiceEndpointNotificationService serviceBusService、IOrganizationServiceFactory organizationServiceFactory、String pluginTypeName、String pluginConfiguration、String pluginSecureConfig、IPluginExecutionContext requestContext) 在 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)
根据一些阅读,我不认为这是一个错误 - 而是因为自定义 Exception
类从 .NET 4 开始就不是本质上受信任的(我使用的是 .NET 4.5 .)
有谁知道如何制作将与 CRM 沙盒一起使用的自定义异常类。我正在使用自定义异常类,因为我捕获了错误并且需要区分 InvalidPluginExecutionException
和由于插件未正确注册而导致的异常。
2014 年 4 月 8 日更新
这是插件中捕获异常的代码,将其放在 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);
}
最佳答案
经过一些额外的测试,这是我能够确定的:
显然,您可以访问 Stack Trace 以查找异常,前提是明确这样做。当从沙盒插件中抛出异常时,只要异常是 CRM 平台“知道”的异常,实际上就不会显示异常的堆栈跟踪(不确定它在做什么,但我猜它是正在查看异常的类型,并以不同的方式处理不同的类型)。如果类型未知,则会导致 CRM 尝试序列化 a 中不允许的异常,因为它使用反射(为什么必须序列化,不确定)。
这是一个示例插件,其中一些示例有效,一些示例无效:
public class TestPlugin: IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
try
{
OtherMethod();
}
catch (Exception ex)
{
var trace = (ITracingService)serviceProvider.GetService(typeof (ITracingService));
trace.Trace("Throwing Plugin");
// Doesn't work
throw new InvalidPluginExecutionException("Error ", ex);
}
}
// Works:
//public void Execute(IServiceProvider serviceProvider)
//{
//try
//{
//OtherMethod();
//}
//catch (Exception ex)
//{
//var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
//trace.Trace("Throwing Plugin");
//throw new InvalidPluginExecutionException("Error " + ex);
//}
//}
// Doesn't Work:
//public void Execute(IServiceProvider serviceProvider)
//{
// try
// {
// OtherMethod();
// }
// catch (Exception ex)
// {
// throw;
// }
//}
// Doesn't Work:
//public void Execute(IServiceProvider serviceProvider)
//{
// try
// {
// OtherMethod();
// }
// catch (Exception ex)
// {
// throw new InvalidPluginExecutionException("Error", ex);
// }
//}
public void OtherMethod()
{
throw new MyException();
}
}
public class MyException : Exception
{
}
所以回答你的问题:我写了一个异常处理程序来处理内部异常并确定抛出它是否有效:
/// <summary>
/// Exception Handler For Exceptions when executing in Sandbox Isolation Mode
/// </summary>
public class ExceptionHandler
{
/// <summary>
/// Determines whether the given exception can be thrown in sandbox mode.
/// Throws a Safe if it can't
/// </summary>
/// <param name="ex">The ex.</param>
/// <returns></returns>
/// <exception cref="InvalidPluginExecutionException"></exception>
/// <exception cref="Exception"></exception>
public static bool CanThrow(Exception ex)
{
var exceptionRootTypeIsValid = IsValidToBeThrown(ex);
var canThrow = exceptionRootTypeIsValid;
var innerException = ex.InnerException;
// While the Exception Types are still valid to be thrown, loop through all inner exceptions, checking for validity
while (canThrow && innerException != null)
{
if (IsValidToBeThrown(ex))
{
innerException = innerException.InnerException;
}
else
{
canThrow = false;
}
}
if (canThrow)
{
return true;
}
var exceptionMessage = ex.Message +
(ex.InnerException == null
? string.Empty
: " Inner Exception: " + ex.InnerException.ToStringWithCallStack());
// ReSharper disable once InvertIf - I like it better this way
if (exceptionRootTypeIsValid)
{
// Attempt to throw the exact Exception Type, with the
var ctor = ex.GetType().GetConstructor(new[] { typeof(string) });
if (ctor != null)
{
throw (Exception) ctor.Invoke(new object[] { exceptionMessage });
}
}
throw new Exception(exceptionMessage);
}
/// <summary>
/// Determines whether the specified ex is valid to be thrown.
/// Current best guess is that it is not
/// </summary>
/// <param name="ex">The ex.</param>
/// <returns></returns>
private static bool IsValidToBeThrown(Exception ex)
{
var assembly = ex.GetType().Assembly.FullName.ToLower();
return assembly.StartsWith("mscorlib,") || assembly.StartsWith("microsoft.xrm.sdk,");
}
}
这可以从你的插件中最上面的 try catch 调用,如下所示:
catch (InvalidPluginExecutionException ex)
{
context.LogException(ex);
// This error is already being thrown from the plugin, just throw
if (context.PluginExecutionContext.IsolationMode == (int) IsolationMode.Sandbox)
{
if (Sandbox.ExceptionHandler.CanThrow(ex))
{
throw;
}
}
else
{
throw;
}
}
catch (Exception ex)
{
// Unexpected Exception occurred, log exception then wrap and throw new exception
context.LogException(ex);
ex = new InvalidPluginExecutionException(ex.Message, ex);
if (context.PluginExecutionContext.IsolationMode == (int)IsolationMode.Sandbox)
{
if (Sandbox.ExceptionHandler.CanThrow(ex))
{
// ReSharper disable once PossibleIntendedRethrow - Wrap the exception in an InvalidPluginExecutionException
throw ex;
}
}
else
{
// ReSharper disable once PossibleIntendedRethrow - Wrap the exception in an InvalidPluginExecutionException
throw ex;
}
}
我相信这是一个真正的错误,我已经向微软开具了支持票,我们将看看他们是否同意...
更新!!
我与 Microsoft 创建了一个票证:(不确定这些数字的含义,但它们在主题中并且希望将来对某人有益:REG:115122213520585 SRXCAP:1318824373ID)。他们确实确认 CRM 中不支持沙盒插件的自定义异常。
请对此投票 Connect Ticket让 Microsoft 修复此问题或至少更好地处理它!
关于c# - CRM 插件 : Custom Exception in Sandbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22889215/
Paypal 最近更改了他们在 developers.paypal 中的用户界面,因此,我找不到可以登录旧 SANDBOX 帐户的位置。 在新的 developer.paypal.com 中,在 Ap
我正在尝试使用 loadPhotoForSize: withCompletionHandler: 为游戏中心的 friend 获取头像但它一直在抛出GKErrorDomain Code=3 "The
我在 paypal developer 中创建了多个沙箱帐户。我已在所有这些帐户上启用 business pro,以便接收直接付款。但是,对于在美国以外的国家/地区创建的商业专业账户,发送直接付款的
我能够使用 node 用户并使用 --cap-add=SYS_ADMIN 设置沙箱使其正常工作,但 AWS ECS Fargate 不支持添加 SYS_ADMIN 作为 linux 参数。因此,我试图
我正在尝试使用 scotty 创建一个简单网站的教程,但是当我尝试命令“cabal sandbox init”时出现错误: cabal: unrecognised command: sandbox (
我想制作一个非常基本的 Excel 插件。但是,在 Excel Online 中加载 xml 文件后出现错误: 有人知道如何修复这些错误吗? 这是 xml 文件: 2145a915-4e7b-
我使用 Ambari 运行了 pig 服务检查,但它失败了并出现以下异常。 2016-04-09 20:35:19,399 [JobControl] INFO org.apache.hadoop.m
我正在尝试将一个Firebase函数部署到使用Pupeteer的FireBase项目中,我让它在我的本地计算机上运行,但当它尝试在FireBase上运行时,我收到以下错误:。我在网上看到其他人说要使用
我已阅读 Wikipedia article ,但我不太确定它的含义,以及它与版本控制有多么相似。 如果有人能用非常简单的术语解释什么是沙箱,那将会很有帮助。 最佳答案 A sandpit or sa
重新访问一个一个月左右没打开的项目,发现之前设置的沙箱账户无法访问,访问; http://admin.wechat.com/debug/cgi-bin/sandbox?t=sandbox/login
Apple 在 WWDC 17 上推出了 ARKit,他们还在 Xcode 9 中添加了一个名为“增强现实应用程序”的新项目模板,它基本上应该是 WWDC 主题演讲或类似事件期间的演示应用程序。 但是
我正在尝试使用 How can I create a secure Lua sandbox?构建我自己的泄漏沙箱。 我正在尝试创建一个 Lua 沙箱,其中一些 Lua 函数可以访问沙箱外的其他一些 L
Hy 这里是一个例子 Example 为什么当我使用 沙箱我看不到播放器..我想使用沙箱来阻止弹出窗口,但看起来如果我使用它我看不到播放器 有没有allow-objects ? 我在那个页面上也有一
我对新的 PayPal 开发人员网站和 Sandbox 感到悲痛。我在 Developer 中创建了一个个人帐户,但我添加的资金没有显示出来。我读过一篇论坛帖子,说您必须通过 Sandbox 登录来添
在沙盒模式下查询 Instagram API 以获取与 token 相关的用户喜欢的媒体,我没有得到任何数据。当然,用户被授权在沙盒中使用该应用程序。 获取:https://api.instagram
我正在开发记录用户音频的应用程序,并在表格 View 的另一个屏幕上显示从此应用程序制作的所有早期录音。单击特定行时,必须播放录音。我如何实现这一目标,是否有任何资源可以帮助我实现同样的目标? 我的代
我有运行 Express Checkout 的沙箱。当我在我的沙盒中使用卖家账户进行测试付款时,一切正常,付款成功,买家账户从中扣除购买金额。但是卖家账户从来没有得到任何钱。 我在某处读到,要激活卖家
谁知道我在哪里可以启用 “商家未启用账单地址请求” 在沙箱环境中? 谢谢达尔科 最佳答案 请打开ticket向 MTS 技术团队提供帮助。 关于paypal-sandbox - 商家未启用账单地址请求
您好,我是 Paypal 集成的新手。 我已在我的在线商店中成功设置了 Express Checkout。 但在我的 Sandbox 帐户中,无论实际值(value)多少,每笔交易的余额总是减少 20
在 Paypal Sandbox 中,当我尝试向买家账户添加信用卡时,我不断收到错误消息“该卡号已分配给另一个 PayPal 账户。”我不明白,因为当我创建测试帐户时,Paypal 刚刚为我生成了号码
我是一名优秀的程序员,十分优秀!