我有一個在沙盒中執行的Dynamics CRM 2013插件。CRM插件:沙盒中的自定義例外
該代碼具有以下自定義異常類:
[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.Runtim e.Serialization.SerializationException:Microsoft Dynamics CRM遇到錯誤。在Microsoft.Crm.Application.Platform.ServiceCommands.CreateCommand.Execute -2147220970 調用堆棧 在Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal() :針對管理員或支持參考號:#1355B4E4Detail () 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.U pdateEntity(實體的實體,布爾檢索) 在Microsoft.Crm.Application.WebServices.InlineEdit.SaveCommand.ExecuteCommand(字符串commandXml) 在Microsoft.Crm.Application.WebServices.InlineEdit.CommandBase.Execute(字符串commandXml) 系統.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 ,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 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)
我不這樣做,根據一些閱讀,認爲這是一個錯誤 - 而這是因爲定製Exception
類不是,本質上是tr從.NET 4開始(我正在使用.NET 4.5。)
有誰知道如何製作一個自定義異常類,它將與CRM Sandbox一起工作。我正在使用自定義異常類,因爲我發現錯誤並需要區分InvalidPluginExecutionException
因插件未正確註冊而導致的異常。
已更新2014年4月8日
這裏是映入例外,有顯著簡化了把它#2插件代碼:
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);
}
我有一個類似的問題。你能解決這個問題嗎? – Daryl
在我的測試中,默認的Exception.StackTrace實現會執行某種序列化,如果Exception不是標準類型(即自定義異常),則會阻止訪問堆棧跟蹤。你見過類似的東西嗎? – Daryl