Add ProfilerAlreadyActiveException in DiagnosticsClient.AttachProfiler() (#1911)
authorMikhail Pilin <ww898@users.noreply.github.com>
Fri, 15 Jan 2021 22:24:11 +0000 (23:24 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Jan 2021 22:24:11 +0000 (14:24 -0800)
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs

index 33ae677b221a3003e96b24b0560efcc3609f310b..6b11c75071a6e88464bd374e95273f260ac849eb 100644 (file)
@@ -140,6 +140,10 @@ namespace Microsoft.Diagnostics.NETCore.Client
                     {
                       throw new UnsupportedCommandException("The target runtime does not support profiler attach");
                     }
+                    if (hr == (uint)DiagnosticsIpcError.ProfilerAlreadyActive)
+                    {
+                        throw new ProfilerAlreadyActiveException("The request to attach a profiler was denied because a profiler is already loaded");
+                    }
                     throw new ServerErrorException($"Profiler attach failed (HRESULT: 0x{hr:X8})");
                 case DiagnosticsServerResponseId.OK:
                     return;
index 5016e4f7e141dde17b4d12fffb793527f73042ad..79ae879d4f6e76848b6fe99c68538350c593af9d 100644 (file)
@@ -34,4 +34,10 @@ namespace Microsoft.Diagnostics.NETCore.Client
     {
         public UnsupportedCommandException(string msg): base(msg) {}
     }
+
+    // When the runtime already has loaded profiler
+    public class ProfilerAlreadyActiveException : ServerErrorException
+    {
+        public ProfilerAlreadyActiveException(string msg): base(msg) {}
+    }
 }
\ No newline at end of file
index b015673e1d875ab834817eefaa32824007288791..372d49ef3d856b8d8d9fb4773ef810ef3f46f144 100644 (file)
@@ -15,10 +15,11 @@ namespace Microsoft.Diagnostics.NETCore.Client
     /// </summary>
     internal enum DiagnosticsIpcError : uint
     {
-        BadEncoding     = 0x80131384,
-        UnknownCommand  = 0x80131385,
-        UnknownMagic    = 0x80131386,
-        UnknownError    = 0x80131387
+        ProfilerAlreadyActive = 0x8013136A,
+        BadEncoding           = 0x80131384,
+        UnknownCommand        = 0x80131385,
+        UnknownMagic          = 0x80131386,
+        UnknownError          = 0x80131387
     }
 
     /// <summary>