0

ComVisible false にする必要があるという StyleCop の CA1017 エラー メッセージが表示されます。

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もこの名前を認識していないようです。

ここに画像の説明を入力

これの何が問題なのですか?

4

1 に答える 1

3

名前空間ComVisibleAttributeで定義されています。System.Runtime.InteropServices

したがって、次のいずれかが必要です。

  1. 属性の名前を名前空間で完全修飾します。

    [assembly: System.Runtime.InteropServices.ComVisible(false)]
    
  2. ソース ファイルの先頭にディレクティブを追加してusing、そのファイルの名前空間をインポートします。

    using System.Runtime.InteropServices;
    

将来的には、Visual Studio でこれらのことについて警告できるようになるはずです。コンパイラ エラーを示す波線が表示されたら、近くにあるドロップダウン ボタンを探すか、Ctrl+キーを押し.ます。メニューが表示され、問題の解決策が示されます。この場合、上記のオプション 1 または 2 のいずれかを選択することをお勧めします。1 回のクリックで、必要なすべてのアクションが実行されます。

     

(上記の素晴らしいアニメーション画像は、ここからリッピングされました。)

于 2011-05-24T15:24:35.643 に答える