Reputation: 1571
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?
Upvotes: 4
Views: 3408
Reputation: 157136
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")]
Upvotes: 4
Reputation: 28366
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
Upvotes: 5