When configuring Atatus environment variables for IIS Application Pools via AppCmd.exe, you may encounter the following error:
ERROR ( message:New add object missing required attributes. Cannot add duplicate collection entry
of type 'add' with unique key attribute 'name' set to 'CORECLR_ENABLE_PROFILING'. )
Cause
This error occurs when the environment variables have already been added to the application pool. IIS does not allow duplicate entries in the environmentVariables collection. Running the configuration script multiple times without removing existing entries will trigger this error.
Solution
Use the following script which removes only the Atatus-managed environment variables listed in the script and re-adds them with updated values. Other environment variables in the application pool are not affected. This makes the script safe to run multiple times without errors.
$appcmd = "$($env:systemroot)\system32\inetsrv\AppCmd.exe"
# Define your application pools and their corresponding Atatus app names
$appPools = @{
"<IISAppPoolName1>" = "<AtatusAppName1>"
"<IISAppPoolName2>" = "<AtatusAppName2>"
}
# Base environment variables (common to all pools)
$environment = @{
CORECLR_ENABLE_PROFILING = "1"
CORECLR_PROFILER = "{A6C28362-6F75-472A-B36C-50C1644DA40A}"
CORECLR_PROFILER_PATH = "<extracted directory>\atatus_profiler.dll"
ATATUS_PROFILER_HOME = "<extracted directory>"
ATATUS_PROFILER_INTEGRATIONS = "<extracted directory>\integrations.yml"
COMPlus_LoaderOptimization = "1"
ATATUS_LICENSE_KEY = "YOUR_LICENSE_KEY"
ATATUS_ANALYTICS = "true"
ATATUS_TRACING = "true"
ATATUS_CAPTURE_BODY = "all"
}
# Apply environment variables per app pool
$appPools.GetEnumerator() | ForEach-Object {
$appPool = $_.Key
$atatusAppName = $_.Value
$envVars = $environment.Clone()
$envVars["ATATUS_APP_NAME"] = $atatusAppName
# Step 1: Remove only the Atatus-managed env vars
$envVars.Keys | ForEach-Object {
& $appcmd set config -section:system.applicationHost/applicationPools `
/-"[name='$appPool'].environmentVariables.[name='$_']" `
/commit:apphost 2>$null | Out-Null
}
# Step 2: Add the new environment variables
$envVars.Keys | ForEach-Object {
& $appcmd set config -section:system.applicationHost/applicationPools `
/+"[name='$appPool'].environmentVariables.[name='$_',value='$($envVars[$_])']"
}
}
# Recycle only the configured app pools to apply changes
$appPools.Keys | ForEach-Object {
& $appcmd recycle apppool /apppool.name:"$_"
}
The above script uses CORECLR_* variables for .NET Core applications. For .NET Framework applications, replace CORECLR_ENABLE_PROFILING, CORECLR_PROFILER, and CORECLR_PROFILER_PATH with COR_ENABLE_PROFILING, COR_PROFILER, and COR_PROFILER_PATH respectively.
+1-415-800-4104