5

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shrike
  • 9,218
  • 7
  • 68
  • 105

1 Answers1

8

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • You're right. I was looking in Reflector at C:\Windows\Microsoft.net\Framework\v4.0.30319\System.Web.dll and forgot that 4.5 is "in-place upgrade". (I do have 4.5 RC installed) – Shrike Aug 03 '12 at 18:33