VS2010 StyleCop与CA1017 ComVisible相关的错误

问题描述

| 我的StyleCop出现CA1017错误消息,提示我需要将其设置为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).
然后,将代码“ 1”放在最顶层的命名空间之前。但是,我仍然遇到相同的错误以及其他错误消息。
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也无法识别此名称。 这怎么了?     

解决方法

“ 3”是在“ 4”命名空间中定义的。 因此,您要么需要: 使用名称空间对属性名称进行完全限定:
[assembly: System.Runtime.InteropServices.ComVisible(false)]
在源文件的顶部添加一个“ 6”指令以导入该文件的名称空间:
using System.Runtime.InteropServices;
将来,您应该能够使用Visual Studio来警告您这些事情。当您看到一条弯曲的线表示编译器错误时,请查找附近的下拉按钮或按Ctrl +。应出现一个菜单,指示可能的问题解决方案。在这种情况下,建议您采用上面列出的选项1或2,并且单击一下即可为您执行所有必要的操作。 (以上惊人的动画图像是从此处撕下的。)     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...