Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why multiple using of PreApplicationStartMethodAttribute isn't compiled?

Tags:

c#

system.web

System.Web.PreApplicationStartMethodAttribute defined as:

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute 
{}

I.e. it allows multiple usage (AllowMultiple=true). But if I try to added several usages of this attribute to my assembly :

[assembly: PreApplicationStartMethod(typeof(MyType1), "Start")]
[assembly: PreApplicationStartMethod(typeof(MyType2), "Start")]

I get compiler error:

Error 2 Duplicate 'PreApplicationStartMethod' attribute

Why is this?

like image 688
Shrike Avatar asked Aug 03 '12 18:08

Shrike


1 Answers

I suspect you were looking at the .NET 4.5 version, which is documented as having AllowMultiple = True.

The documentation for the .NET 4.0 version shows it as AllowMultiple = false:

[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute

So if you target .NET 4.5, it should be okay.

like image 187
Jon Skeet Avatar answered Nov 17 '22 13:11

Jon Skeet