Page 5 of 10               << Previous  1  2  3  4  5  6  7  8  9  10  Next >>


Custom FxCop Rule - Do Use the VB Compatibility Namespace

The Microsoft VisualBasic Compatability namespace is used to invoke older VB6 functionality in VB.NET code. To use this namespace, you need to set a reference to it. So to test for this we can look at the assemblies referenced by our assembly.

C# code for custom FxCop rule:

using System;
using Microsoft.Cci;
using Microsoft.FxCop.Sdk;
using Microsoft.FxCop.Sdk.Introspection;

public class DoNotUseVBCompatibilityNamespace : BaseMigrationIntrospectionRule
    public DoNotUseVBCompatibilityNamespace()
        : base("DoNotUseVBCompatibilityNamespace")

    public override ProblemCollection Check(Module module)
        if (module == null)
            return base.Check(module);

        AssemblyReferenceList refList = module.AssemblyReferences;
        foreach (AssemblyReference reference in refList)
            if (reference.Name.ToUpper().Contains("MICROSOFT.VISUALBASIC.COMPATIBILITY"))
                base.Problems.Add(new Problem(GetResolution(module.Name), module));

        return base.Problems;

Rule definition in the XML rules file:

<Rule TypeName="DoNotUseVBCompatibilityNamespace" 
          Category="VBMigration" CheckId="AA1001">
        Do not use 'Microsoft.VisualBasic.Compatibility' namespace
        Avoid dependency on the Microsoft.VisualBasic.Compatibility namespace
        '{0}' has imported the namespace of 'Microsoft.VisualBasic.Compatibility' or 
        'Microsoft.VisualBasic.Compatibility.Data'. Replace the code that references this 
        namespace with the .NET equivalent
    <MessageLevel Certainty="99">
    <Owner />


Page 5 of 10               << Previous  1  2  3  4  5  6  7  8  9  10  Next >>

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2019 TheScarms
Goto top of page