[英]Why multiple using of PreApplicationStartMethodAttribute isn't compiled?
System.Web.PreApplicationStartMethodAttribute defined as: System.Web.PreApplicationStartMethodAttribute定义为:
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute
{}
Ie it allows multiple usage (AllowMultiple=true). 即它允许多次使用(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
错误2重复'PreApplicationStartMethod'属性
Why is this? 为什么是这样?
I suspect you were looking at the .NET 4.5 version , which is documented as having AllowMultiple = True
. 我怀疑你在看.NET 4.5版本 ,它被记录为具有
AllowMultiple = True
。
The documentation for the .NET 4.0 version shows it as AllowMultiple = false
: .NET 4.0版本的文档将其显示为
AllowMultiple = false
:
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute
So if you target .NET 4.5, it should be okay. 因此,如果你的目标是.NET 4.5,它应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.