{"record":{"id":"b07e0c17f27ce5d7","repo":"dotnet/runtime","slug":"method-instrumentation-is-not-enabled-please-enab","errorCode":null,"errorMessage":"method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property","messagePattern":"method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/diagnostics/dotnet-cpu-profiler.ts","lineNumber":17,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport type { DiagnosticCommandOptions } from \"../types\";\n\nimport { commandStopTracing, commandSampleProfiler } from \"./client-commands\";\nimport { loaderHelpers, Module, runtimeHelpers } from \"./globals\";\nimport { serverSession, setupJsClient } from \"./diagnostics-js\";\nimport { IDiagnosticSession } from \"./common\";\n\nexport function collectCpuSamples (options?:DiagnosticCommandOptions):Promise<Uint8Array[]> {\n    if (!options) options = {};\n    if (!serverSession) {\n        throw new Error(\"No active JS diagnostic session\");\n    }\n    if (!runtimeHelpers.config.environmentVariables![\"DOTNET_WasmPerformanceInstrumentation\"]) {\n        throw new Error(\"method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property\");\n    }\n\n    const onClosePromise = loaderHelpers.createPromiseController<Uint8Array[]>();\n    function onSessionStart (session: IDiagnosticSession): void {\n        // stop tracing after period of monitoring\n        Module.safeSetTimeout(() => {\n            session.sendCommand(commandStopTracing(session.session_id));\n        }, 1000 * (options?.durationSeconds ?? 60));\n    }\n\n    setupJsClient({\n        onClosePromise:onClosePromise.promise_control,\n        skipDownload:options.skipDownload,\n        commandOnAdvertise: () => commandSampleProfiler(options),\n        onSessionStart,\n    });\n    return onClosePromise.promise;\n}","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/diagnostics/dotnet-cpu-profiler.ts#L1-L35","documentation":"Thrown by `collectCpuSamples` after the session check passes, when the runtime was built without method instrumentation. The sampler needs the `DOTNET_WasmPerformanceInstrumentation` environment variable to be set at build time (via the `WasmPerformanceInstrumentation` MSBuild property); without it, the profiler has no instrumented methods to sample.","triggerScenarios":"Calling `collectCpuSamples` (dotnet-cpu-profiler.ts:16) when `runtimeHelpers.config.environmentVariables['DOTNET_WasmPerformanceInstrumentation']` is unset. This variable is injected by the SDK only when `<WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation>` is in the project.","commonSituations":"Default publish (no instrumentation); profiling a release build that explicitly disabled instrumentation; forgetting to add the MSBuild property before publishing.","solutions":["Add `<WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation>` to the .csproj and republish.","Confirm `runtimeHelpers.config.environmentVariables` actually contains the key after publish (check the generated config).","Use a build configuration that enables instrumentation for profiling runs."],"exampleFix":"// before: default publish\n//  <Project Sdk=\"Microsoft.NET.Sdk.Web\">\n//   ...\n//  </Project>\n// collectCpuSamples() throws\n\n// after: enable in .csproj\n<Project Sdk=\"Microsoft.NET.Sdk.Web\">\n  <PropertyGroup>\n    <WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation>\n  </PropertyGroup>\n</Project>","handlingStrategy":"validation","validationCode":"function isInstrumentationEnabled () {\n  return !!runtimeHelpers.config.environmentVariables?.['DOTNET_WasmPerformanceInstrumentation'];\n}\nif (!isInstrumentationEnabled()) console.warn('rebuild with <WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation>');","typeGuard":"function instrumentationEnabled (env: Record<string,string|undefined>): boolean {\n  return !!env?.['DOTNET_WasmPerformanceInstrumentation'];\n}","tryCatchPattern":null,"preventionTips":["Add `<WasmPerformanceInstrumentation>true</WasmPerformanceInstrumentation>` to profiling builds.","Gate the profiler UI on a build-flag the app sets at publish time.","Document that release builds ship without instrumentation by default."],"tags":["diagnostics","cpu-profiler","msbuild","configuration","instrumentation"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}