Skip to content

Commit 3cd985b

Browse files
Handle the fact the Net Standard can be Core or Framework
1 parent c753afd commit 3cd985b

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

Src/StackifyLib/Utils/HelperFunctions.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22
using System;
33
using System.Collections.Generic;
4+
using System.ComponentModel.Design;
45
using System.Linq;
56
using System.Reflection;
67
#if NETFRAMEWORK
@@ -552,8 +553,38 @@ protected static bool IsBeingProfiled
552553
var profilerEnv = "COR_ENABLE_PROFILING";
553554
var profilerUuidEnv = "COR_PROFILER";
554555
#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+
}
557588
#endif
558589

559590
var enableString = Environment.GetEnvironmentVariable(profilerEnv);

0 commit comments

Comments
 (0)