Writing Custom Rules for VS 2008 Code Analysis - What a Pain!
I am close to giving up.
With every single effin' upgrade to FxCop, the API breaks so badly that any former rules go haywire. So I have to spend hours of hacking and searching to try and figure out what the hell changed and how I can address it. The big problem now is that I have to use
RuleUtilities.GetAssembly() to get a
TypeNode, but that always throws a
NullReferenceException, even though the file name I pass in is perfectly valid.
I really like Code Analysis, but I am so tired using an undocumented API.
Update: I'm guessing CommonUtilities is null...which means that something has to load it.
Update: Ha! HA, HA, HA! Think custom rules can't be tested? I think this is a promising start:
public void Initialize()
AssemblyName commonAsmName = new AssemblyName(
"FxCopCommon, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Assembly commonAsm = Assembly.Load(commonAsmName);
Type prov = commonAsm.GetType(
if(prov != null)
object provInst = Activator.CreateInstance(prov, true);
AssemblyName sdkAsmName = new AssemblyName(
"FxCopSdk, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Assembly sdkAsm = Assembly.Load(sdkAsmName);
Type intUtil = sdkAsm.GetType("Microsoft.FxCop.Sdk.InternalUtilities", false);
if(intUtil != null)
"s_commonUtilities", BindingFlags.NonPublic | BindingFlags.Static)
We'll see if this holds up...
Update: One step back...getting an error in ResolveAssemblyReference in CommonUtilitiesProvider...
* Posted at 03.30.2008 03:28:53 PM CST | Link *