DiagnosticMonitor.Start() line in OnStart() method generates exception: The remote server returned an error: (409) Conflict.

Recently I was working on an issue in which DiagnosticMonitor.Start() line in OnStart() method was generating exception as below:

Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code

  Message=The specified container already exists.

  Source=Microsoft.WindowsAzure.StorageClient

  StackTrace:

       at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender)

       at Microsoft.WindowsAzure.StorageClient.CloudBlobClient.EndGetResponse(IAsyncResult asyncresult, WebRequest req)

       at Microsoft.WindowsAzure.StorageClient.Tasks.WebRequestExtensions.<>c__DisplayClass1.<GetResponseAsync>b__0(IAsyncResult asyncresult)

       at Microsoft.WindowsAzure.StorageClient.Tasks.APMTask`1.OnEnd(IAsyncResult ar)

  InnerException: System.Net.WebException

       Message=The remote server returned an error: (409) Conflict.

       Source=System

       StackTrace:

            at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

            at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender)

       InnerException:

I found that this exception was caused by following two properties:

1. I had “Just My Code” enabled in my

2. My exception policy was set to “Break on uncaught exception in user code”.

The exception stopped appearing after I made following two chances in my VS2010 environment:

1. Tools > Options > Debugging > General > Enable Just My Code <------- Uncheck/Disable

2. Debug > Exceptions > Break on uncaught exception in user code <------- Uncheck/Disable