title: 2 Minute Plugin Time Out Unhandled Exception
body: <p>I'm trying to simulate a 2 minute time out on my Plugin by using Thread.Sleep(120000) to generate a Time Out but when that exception arises my try catch can't seem to catch them, even the finally block is skipped.</p>
  
  <p>How would i properly catch it so that i can perform on creating a case record on this error?</p>
  
  <p>I've tried using different catch exceptions to no avail. I've even tried profiling the plugin but it also won't profile the plugin due to the error.</p>
  
  <pre><code>protected override void ExecuteCrmPlugin(LocalPluginContext localContext) {
  
          IPluginExecutionContext context = localContext.PluginExecutionContext;
          IOrganizationService service = localContext.OrganizationService;
          ITracingService tracer = localContext.TracingService;
  
          try {
              if (context.InputParameters.Contains("Target") &amp;&amp; context.InputParameters["Target"] is Entity) {
  
                  Entity entity = (Entity)context.InputParameters["Target"];
  
                  if (context.MessageName.ToLower() != "create")
                      return;
  
                  if (entity.LogicalName.ToLower() == Contact.EntityLogicalName) {
                      tracer.Trace("Sleep for 2 min");
                      Thread.Sleep(120000);
                  }
              }
          }
  
          catch (System.ServiceModel.FaultException&lt;System.TimeoutException ex) {
              throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
          }
          catch (System.ServiceModel.FaultException&lt;Microsoft.Xrm.Sdk.OrganizationServiceFault ex) {
              throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
          }
          catch (TimeoutException e) {
              throw new InvalidPluginExecutionException("A timeout has occurred during the execution of the plugin.", e);
          }
          catch (FaultException ex) {
              throw new InvalidPluginExecutionException("Err occurred.", ex);
          }
          catch (Exception ex) {
              tracer.Trace(ex.ToString());
              throw;
          }
          finally {
              tracer.Trace("Finally");
          }
      }
  </code></pre>
  
  <p>In the Base Class I also have the same catch blocks.</p>
  
  <p>The error is:</p>
  
  <pre><code>Unhandled exception: 
  Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
  Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute):  MyPlugin.Plugins.PreCreateContact: System.TimeoutException: Couldn’t complete execution of the MyPlugin.Plugins.PreCreateContact plug-in within the 2-minute limit.Detail:
  
  &lt;OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"&gt;
    &lt;ActivityId&gt;397e0f4c-2e16-43ea-9368-ea76607820a5&lt;/ActivityId&gt;
    &lt;ErrorCode&gt;-2147220956&lt;/ErrorCode&gt;
    &lt;ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /&gt;
    &lt;HelpLink i:nil="true" /&gt;
    &lt;Message&gt;An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute):  MyPlugin.Plugins.PreCreateContact: System.TimeoutException: Couldn’t complete execution of the MyPlugin.Plugins.PreCreateContact plug-in within the 2-minute limit.&lt;/Message&gt;
    &lt;Timestamp&gt;2019-07-17T00:49:48.360749Z&lt;/Timestamp&gt;
    &lt;ExceptionRetriable&gt;false&lt;/ExceptionRetriable&gt;
    &lt;ExceptionSource&gt;PluginExecution&lt;/ExceptionSource&gt;
    &lt;InnerFault i:nil="true" /&gt;
    &lt;OriginalException&gt;System.TimeoutException: Couldn’t complete execution of the MyPlugin.Plugins.PreCreateContact plug-in within the 2-minute limit.
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, Dictionary`2 sandboxServices, String pluginTypeName, String pluginConfiguration, String pluginSecureConfig, IPluginExecutionContext requestContext, Boolean enablePluginStackTrace, Boolean chaosFailAppDomain, String crashOnPluginExceptionMessage)
     at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, Dictionary`2 sandboxServices, String pluginTypeName, String pluginConfiguration, String pluginSecureConfig, IPluginExecutionContext requestContext, Boolean enablePluginStackTrace, Boolean chaosFailAppDomain, String crashOnPluginExceptionMessage)
     at Microsoft.Crm.Sandbox.SandboxWorker.&amp;lt;&amp;gt;c__DisplayClass3_0.&amp;lt;Execute&amp;gt;b__0()&lt;/OriginalException&gt;
    &lt;TraceText&gt;
  Entered MyPlugin.Plugins.PreCreateContact.Execute(), Correlation Id: 0c2b0dd3-d27c-46ea-a7e2-90c0729b326e, Initiating User: 61e01dfa-668a-e811-8107-123456
  &lt;/TraceText&gt;
  &lt;/OrganizationServiceFault&gt;
  </code></pre>