|
1 | 1 | using Newtonsoft.Json; |
2 | 2 | using System; |
3 | 3 | using System.Collections.Generic; |
| 4 | +using System.ComponentModel.Design; |
4 | 5 | using System.Linq; |
5 | 6 | using System.Reflection; |
6 | 7 | #if NETFRAMEWORK |
@@ -552,8 +553,38 @@ protected static bool IsBeingProfiled |
552 | 553 | var profilerEnv = "COR_ENABLE_PROFILING"; |
553 | 554 | var profilerUuidEnv = "COR_PROFILER"; |
554 | 555 | #else |
555 | | - var profilerEnv = "CORECLR_ENABLE_PROFILING"; |
556 | | - var profilerUuidEnv = "CORECLR_PROFILER"; |
| 556 | + string profilerEnv = null; |
| 557 | + string profilerUuidEnv = null; |
| 558 | + |
| 559 | + // .Net Standard could be .Net Core or .Net Framework, so check |
| 560 | + var framework = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; |
| 561 | + |
| 562 | + if (string.IsNullOrEmpty(framework)) |
| 563 | + { |
| 564 | + return false; |
| 565 | + } |
| 566 | + |
| 567 | + if (framework.StartsWith(".NET Native", StringComparison.OrdinalIgnoreCase)) |
| 568 | + { |
| 569 | + // Native code can't be profiled |
| 570 | + return false; |
| 571 | + } |
| 572 | + else if (framework.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase)) |
| 573 | + { |
| 574 | + profilerEnv = "COR_ENABLE_PROFILING"; |
| 575 | + profilerUuidEnv = "COR_PROFILER"; |
| 576 | + } |
| 577 | + else // Assume everything else is .Net Core current values would be .Net Core, .Net 5.x and .Net 6.x |
| 578 | + { |
| 579 | + profilerEnv = "CORECLR_ENABLE_PROFILING"; |
| 580 | + profilerUuidEnv = "CORECLR_PROFILER"; |
| 581 | + } |
| 582 | + |
| 583 | + if (profilerEnv == null || profilerUuidEnv == null) |
| 584 | + { |
| 585 | + // This code should be unreachable, but just in case the above checks are changed we handle it |
| 586 | + return false; |
| 587 | + } |
557 | 588 | #endif |
558 | 589 |
|
559 | 590 | var enableString = Environment.GetEnvironmentVariable(profilerEnv); |
|
0 commit comments