"System.Guid" is not an attribute class

I am creating a new dll application with Visual Studio 2013 based on .net 4.5. When trying to define an attribute Guidin my class as follows:

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

The compiler gives me an error

'System.Guid' is not an attribute class.

Any idea what is missing?

+4
source share
2 answers

You must specify the correct namespace or operator using. If you do not, it will match System.Guid(instead System.Runtime.InteropServices.GuidAttribute, the part has Attributebeen removed for our convenience), which is really not an attribute. This is a bit confusing, but true ...

:

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

System.Runtime.InteropServices, :

using System.Runtime.InteropServices;

:

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

postfix Attribute:

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

postfix Attribute:

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

MSDN

+5

All Articles