Question

I have CA1017 error message with StyleCop saying I need to make it ComVisible false.

Error   18  CA1017 : Microsoft.Design : 
Because 'NationalInstruments.Labview.FPGA.ModelsimCommunicator.dll' exposes externally 
visible types, mark it with ComVisible(false) at the assembly level and then mark all 
types within the assembly that should be exposed to COM clients with ComVisible(true).

Then, I put the code [assembly: ComVisible(false)] before the topmost namespace. However, I still got the same error together with other error messages.

Error   19  The type or namespace name 'ComVisible' could not be found (are you 
missing a using directive or an assembly reference?)    


Error   20  The type or namespace name 'ComVisibleAttribute' could not be found (are
you missing a using directive or an assembly reference?)    

It seems that VS2010 also doesn't recognize this name.

enter image description here

What's wrong with this?

Était-ce utile?

La solution

The ComVisibleAttribute is defined in the System.Runtime.InteropServices namespace.

So you either need to:

  1. Fully-qualify the attribute's name with its namespace:

    [assembly: System.Runtime.InteropServices.ComVisible(false)]
    
  2. Add a using directive to the top of your source file to import the namespace for that file:

    using System.Runtime.InteropServices;
    

In the future, you should be able to get Visual Studio to warn you about these things. When you see a squiggly line denoting a compiler error, look for the drop-down button that's nearby or press Ctrl+. A menu should appear, indicating possible solutions for the problem. In this case, it would have suggested that you take either option 1 or 2 listed above, and with a single click, would have performed all of the necessary actions for you.

     

(The above amazing animated image was ripped from here.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top