Search code examples
c#visual-studio-2013.net-4.0.net-4.5class-attributes

'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 the Guid attribute on my class like this:

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

The compiler gives me the error

'System.Guid' is not an attribute class.

Any idea what's missing?


Solution

  • 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")]