为什么要使用多的PreApplicationStartMethodAttribute不遵守? [英] Why multiple using of PreApplicationStartMethodAttribute isn't complied?
问题描述
System.Web.PreApplicationStartMethodAttribute定义为:
System.Web.PreApplicationStartMethodAttribute defined as:
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class PreApplicationStartMethodAttribute : Attribute
{}
即它允许多个使用(的AllowMultiple = TRUE)。
但是,如果我尝试添加了一些这个属性的用法我总成:
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")]
我收到编译器错误:结果
错误2重复'PreApplicationStartMethod'属性。
I get compiler error:
Error 2 Duplicate 'PreApplicationStartMethod' attribute
这是为什么
推荐答案
我怀疑你是在看的。NET 4.5版本,它被记录为具有的AllowMultiple = TRUE
。
I suspect you were looking at the .NET 4.5 version, which is documented as having AllowMultiple = True
.
对于文档在.NET 4.0版本显示为的AllowMultiple = FALSE
:
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class PreApplicationStartMethodAttribute : Attribute
所以,如果你的目标.NET 4.5,它应该没问题。
So if you target .NET 4.5, it should be okay.
这篇关于为什么要使用多的PreApplicationStartMethodAttribute不遵守?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!