Why is multiple use of PreApplicationStartMethodAttribute not fulfilled?

System.Web.PreApplicationStartMethodAttribute is defined as:

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

those. it is reusable (AllowMultiple = true). But if I try to add several attributes of this attribute to my assembly:

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

I get a compiler error:
Error 2 Duplicate Attribute "PreApplicationStartMethod"

Why is this?

+5
source share
1 answer

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

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

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

So, if you are targeting .NET 4.5, everything should be fine.

+7
source

All Articles