2011-05-24 36 views
0

我有CA1017错误消息与StyleCop说我需要使它ComVisible错误。CA1017与VS2010 ComVisible相关的错误StyleCop

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). 

然后,我把代码[assembly: ComVisible(false)]放在最顶层的命名空间之前。但是,我仍然遇到了与其他错误消息一样的错误。

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?)  

看来VS2010也不认识这个名字。

enter image description here

这有什么错呢?

回答

3

ComVisibleAttributeSystem.Runtime.InteropServices namespace中定义。

所以,你要么需要:

  1. 其命名综限定属性的名称:

    [assembly: System.Runtime.InteropServices.ComVisible(false)] 
    
  2. 添加using指令源文件导入命名空间的顶部对于该文件:

    using System.Runtime.InteropServices; 
    

将来,您应该能够让Visual Studio警告您这些事情。当您看到表示编译器错误的波浪线时,请查找附近的下拉按钮或按Ctrl + 应出现一个菜单,指出可能的解决方案。在这种情况下,它会建议您采用上面列出的选项1或2,只需点击一下,就可以为您执行所有必要的操作。

         

(以上惊人的动画图像是从here撕开。)