'System.Guid'不是属性类

cod*_*dea 4 c# .net-4.0 class-attributes .net-4.5 visual-studio-2013

我正在使用基于.net 4.5的Visual Studio 2013创建一个新的dll应用程序.尝试Guid在我的类上定义属性时,如下所示:

[Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]
Run Code Online (Sandbox Code Playgroud)

编译器给我错误

'System.Guid'不是属性类.

知道缺少什么吗?

VMA*_*Atm 5

您必须添加System.Runtime.InteropServices对此的引用,如下所示:

using System.Runtime.InteropServices;
Run Code Online (Sandbox Code Playgroud)

或者说明班级的全名:

[System.Runtime.InteropServices.Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]
Run Code Online (Sandbox Code Playgroud)

或使用带有后缀的类名Attribute:

[GuidAttribute("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]
Run Code Online (Sandbox Code Playgroud)

或使用带有后缀的完整类名Attribute:

[System.Runtime.InteropServices.GuidAttribute("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")]
Run Code Online (Sandbox Code Playgroud)

您可以在MSDN文章中找到更多信息