Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do assembly attributes go?

Tags:

c#

attributes

This seems like a silly question, but are there rules for where you can put Assembly specific attributes (which would be terrible if true)? For example if I try to put:

[assembly: RadAttribute]

in a class, it just laughs at me and pretends like it doesn't know what RadAttribute is. I do notice that AssemblyInfo.cs seems to contain some assembly specific attributes, so why is it that they can go in there, but nowhere else?

like image 667
sircodesalot Avatar asked Jun 29 '13 22:06

sircodesalot


People also ask

What are assembly attributes?

Assembly attributes are values that provide information about an assembly. The attributes are divided into the following sets of information: Assembly identity attributes. Informational attributes.

How do I add attributes to assembly level?

Apply attributes at the assembly levelWhen this attribute is applied, the string "My Assembly" is placed in the assembly manifest in the metadata portion of the file. You can view the attribute either by using the MSIL Disassembler (Ildasm.exe) or by creating a custom program to retrieve the attribute.

Which file contains information about the attribute information of an assembly?

An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes.

Which attribute Cannot be applied at the assembly level?

Custom attribute cannot be applied to an assembly.


2 Answers

Assembly attributes like that must be before any namespace or class (or other type) declarations in the code file in question.

like image 121
Jeppe Stig Nielsen Avatar answered Sep 23 '22 10:09

Jeppe Stig Nielsen


I'd usually put it outside of any class declarations, and indeed namespace declarations.

It could go anywhere (except within a class), and AssemblyInfo.cs has no special properties - but is simply a place used by convention to store assembly attributes.

like image 44
Rob G Avatar answered Sep 22 '22 10:09

Rob G