简体   繁体   English

'System.Guid'不是属性类

[英]'System.Guid' is not an attribute class

I am creating a new dll application with Visual Studio 2013 based on .net 4.5. 我正在使用基于.net 4.5的Visual Studio 2013创建一个新的dll应用程序。 When trying to define the Guid attribute on my class like this: 当我尝试在我的类上定义Guid属性时,如下所示:

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

The compiler gives me the error 编译器给我错误

'System.Guid' is not an attribute class. 'System.Guid'不是属性类。

Any idea what's missing? 知道缺少什么吗?

You must add reference to the System.Runtime.InteropServices , like this: 您必须添加对System.Runtime.InteropServices引用,如下所示:

using System.Runtime.InteropServices;

or state the full name for the class: 或者说明班级的全名:

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

or use class name with postfix Attribute : 或使用带有postfix Attribute类名:

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

or use full class name with postfix Attribute : 或使用带有postfix Attribute完整类名:

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

You can find more information on MSDN article 您可以在MSDN文章中找到更多信息

You should include the correct namespace or using statement. 您应该包含正确的命名空间或using语句。 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. 如果你不这样做,它将匹配System.Guid (而不是System.Runtime.InteropServices.GuidAttribute ,为了方便我们删除了Attribute部分),这确实不是一个属性。 It's a little confusing, but true... 这有点令人困惑,但真实......

This code will get you there: 这段代码可以帮到你:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM