微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VS2010 StyleCop与CA1017 ComVisible相关的错误

如何解决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,并且单击一下即可为您执行所有必要的操作。 (以上惊人的动画图像是从此处撕下的。)     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。