Question

I've inherited a large legacy ASP.NET application where I work, and our company wants us to use FxCop and fix all major rule violations. Currently a rule that seems to be prevalent is the following:

CA1405: COM visible type base types should be COM visible

It appears that every ASP.NET page/control in our application is violating this rule. I wasn't sure why at first, but eventually I realized it is due to the following inheritance chain:

System.IDisposable
  → System.Web.UI.Control
    → System.Web.UI.TemplateControl
      → System.Web.UI.Page

I also realized IDisposable is defined as:

[ComVisible(true)]
public interface IDisposable
{
  void Dispose();
}

To summarize: all ASP.NET pages/controls inherit from IDisposable, and IDisposable has the [ComVisible(true)] attribute, which means all pages/controls will fail this rule.

This is hurting us because our application has thousands of pages and controls, and thus thousands of violations. Disabling the rule is not an option, as we have a "company standard" set of FxCop rules. It seems that FxCop wants us to go through and put this attribute on every single page in our application, which I really am not interested in doing.

My question is, why does IDisposable have the [ComVisible(true)] attribute in the first place?

Was it helpful?

Solution

IDisposable is marked as COMVisible in order to allow disposal of resources when a .Net component is used in a COM application.

We actually used this heavily when transitioning from a VB6 application to a full .Net application: we were able to reuse .Net functionality (database access) in a a legacy VB6 application, but had to use the IDispose interface to ensure things such as database connections were correctly cleaned up when we were done using the object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top