4

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?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
codea
  • 1,439
  • 1
  • 17
  • 31
  • the problem is clearly stated in the error message. `"System.Guid' is not an attribute class."` you are looking for [GuidAttribute](http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.guidattribute%28v=vs.100%29.aspx) – Selman Genç Jan 13 '15 at 16:15

2 Answers2

5

You must add reference to the System.Runtime.InteropServices, like this:

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:

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

or use full class name with postfix Attribute:

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

You can find more information on MSDN article

VMAtm
  • 27,943
  • 17
  • 79
  • 125
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")]
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325