4

.net 4.5 ベースの Visual Studio 2013 で新しい dll アプリケーションを作成しています。Guid次のようにクラスで属性を定義しようとすると:

[Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]

コンパイラは私にエラーを与えます

「System.Guid」は属性クラスではありません。

何が欠けているか分かりますか?

4

2 に答える 2

5

System.Runtime.InteropServices次のように、への参照を追加する必要があります。

using System.Runtime.InteropServices;

または、クラスの完全な名前を述べます。

[System.Runtime.InteropServices.Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]

または接尾辞でクラス名を使用しますAttribute

[GuidAttribute("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]

または接尾辞付きの完全なクラス名を使用しますAttribute:

[System.Runtime.InteropServices.GuidAttribute("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]

詳細については、MSDN の記事を参照してください。

于 2015-01-13T16:15:08.040 に答える
4

You should include the correct namespace or using statement. If you don't do that, it will match System.Guid (instead of System.Runtime.InteropServices.GuidAttribute, the Attribute part is stripped out for our convenience), which indeed isn't an attribute. It's a little confusing, but true...

This code will get you there:

[System.Runtime.InteropServices.Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]
于 2015-01-13T16:15:24.220 に答える