Event Id 4001 – “Cannot Add Type” in [#SQL] MP for [#OpsMgr2012]

  1. A wild work-around appears!

Was troubleshooting this little error message for a customer after deploying the SQL Server Management Pack version

The event is the generic “Health Service Script” with id 4001.

Management Group: REDACTED. Script: Main Module: CPUUsagePercentDataSource.ps1 :
Computer Name = "REDACTED.redacted.com" WMI = "ComputerManagement11" Service Name = "MSSQLSERVER" SQL Instance Name = "MSSQLSERVER"
Error occured during CPU Usage for SQL Instances data source executing.
Computer: REDACTED
Reason: Cannot add type. Compilation errors occurred.
Detailed error output: Cannot add type. Compilation errors occurred.
(0) : No source files specified

(1) : using System;

(0) : Source file "C:\Windows\TEMP\njdqtgfb.0.cs" could not be found

(1) : using System;

There are some known errors to the version of the SQL management packs, and one of them does mention “Cannot add type. Compilation errors occured.”
In a thread on the Technet Forums it was suggested that it has to do with rights, but focusing mainly on the SQL instance. What caught our eyes, however, was the fact that the script is using the C:\Windows\TEMP folder instead of its private one. And this seems to be because it is using a few .Net components that do some sort of JIT compilation.
We took a quick look using procmon, filtered on C:\Windows\TEMP\ and yes indeed. The monitoring account used is trying to create and delete its temporary files in that very folder.

A wild work-around appears!

The work-around is simple, but cumbersome. Just make sure that the assigned RunAs account have read/write/delete rights on C:\Windows\TEMP.
Now you just have to manage this on all your SQL-servers! (yaaaay)