C# 为什么PreApplicationStartMethodAttribute的多次使用不是';没有编译?

C# 为什么PreApplicationStartMethodAttribute的多次使用不是';没有编译?,c#,system.web,C#,System.web,System.Web.PreApplicationStartMethodAttribute定义为: [AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)] public sealed class PreApplicationStartMethodAttribute : Attribute {} 也就是说,它允许多次使用(AllowMultiple=true)。 但如果我尝试将此属性的几个用法添加到我的程序集中: [ass

System.Web.PreApplicationStartMethodAttribute定义为:

[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute 
{}
也就是说,它允许多次使用(AllowMultiple=true)。 但如果我尝试将此属性的几个用法添加到我的程序集中:

[assembly: PreApplicationStartMethod(typeof(MyType1), "Start")]
[assembly: PreApplicationStartMethod(typeof(MyType2), "Start")]
我发现编译器错误:

错误2重复“PreApplicationStartMethod”属性


这是为什么?

我怀疑您正在查看,它被记录为具有
AllowMultiple=True

显示为
AllowMultiple=false

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

因此,如果您以.NET 4.5为目标,那么应该没问题。

您是对的。我在Reflector中查看了C:\Windows\Microsoft.net\Framework\v4.0.30319\System.Web.dll,但忘记了4.5是“就地升级”。(我确实安装了4.5 RC)